diff --git a/client_test.go b/client_test.go index 72dfd082..02ccdaf3 100644 --- a/client_test.go +++ b/client_test.go @@ -543,6 +543,22 @@ func TestClientAllowsGetMethodPayload(t *testing.T) { assertEqual(t, payload, resp.String()) } +func TestClientAllowsGetMethodPayloadIoReader(t *testing.T) { + ts := createGetServer(t) + defer ts.Close() + + c := dc() + c.SetAllowGetMethodPayload(true) + + payload := "test-payload" + body := bytes.NewReader([]byte(payload)) + resp, err := c.R().SetBody(body).Get(ts.URL + "/get-method-payload-test") + + assertError(t, err) + assertEqual(t, http.StatusOK, resp.StatusCode()) + assertEqual(t, payload, resp.String()) +} + func TestClientAllowsGetMethodPayloadDisabled(t *testing.T) { ts := createGetServer(t) defer ts.Close() diff --git a/middleware.go b/middleware.go index 362df3b8..57a62703 100644 --- a/middleware.go +++ b/middleware.go @@ -163,7 +163,7 @@ CL: func createHTTPRequest(c *Client, r *Request) (err error) { if r.bodyBuf == nil { - if reader, ok := r.Body.(io.Reader); ok { + if reader, ok := r.Body.(io.Reader); ok && isPayloadSupported(r.Method, c.AllowGetMethodPayload) { r.RawRequest, err = http.NewRequest(r.Method, r.URL, reader) } else if c.setContentLength || r.setContentLength { r.RawRequest, err = http.NewRequest(r.Method, r.URL, http.NoBody)