Skip to content

Commit 6cd1558

Browse files
authored
Add body to http.Request and roundTripper.request to extend conformance util. (#3853)
1 parent 17a60f6 commit 6cd1558

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

conformance/utils/http/http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Request struct {
7070
Headers map[string]string
7171
UnfollowRedirect bool
7272
Protocol string
73+
Body string
7374
}
7475

7576
// ExpectedRequest defines expected properties of a request that reaches a backend.
@@ -139,6 +140,7 @@ func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, sch
139140
Protocol: expected.Request.Protocol,
140141
Headers: map[string][]string{},
141142
UnfollowRedirect: expected.Request.UnfollowRedirect,
143+
Body: expected.Request.Body,
142144
}
143145

144146
if expected.Request.Headers != nil {

conformance/utils/roundtripper/roundtripper.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"net/http/httputil"
3030
"net/url"
3131
"regexp"
32+
"strings"
3233
"testing"
3334

3435
"golang.org/x/net/http2"
@@ -59,6 +60,7 @@ type Request struct {
5960
CertPem []byte
6061
KeyPem []byte
6162
Server string
63+
Body string
6264
}
6365

6466
// String returns a printable version of Request for logging. Note that the
@@ -194,7 +196,12 @@ func (d *DefaultRoundTripper) defaultRoundTrip(request Request, transport http.R
194196
ctx, cancel := context.WithTimeout(context.Background(), d.TimeoutConfig.RequestTimeout)
195197
defer cancel()
196198
ctx = withT(ctx, request.T)
197-
req, err := http.NewRequestWithContext(ctx, method, request.URL.String(), nil)
199+
200+
var reqBody io.Reader
201+
if request.Body != "" {
202+
reqBody = strings.NewReader(request.Body)
203+
}
204+
req, err := http.NewRequestWithContext(ctx, method, request.URL.String(), reqBody)
198205
if err != nil {
199206
return nil, nil, err
200207
}

0 commit comments

Comments
 (0)