Skip to content

Commit

Permalink
fix: SetAllowGetMethodPayload inconsistent behaviour for #541 #618
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 17, 2023
1 parent cd394d0 commit 30fc88b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 30fc88b

Please sign in to comment.