Skip to content

Commit

Permalink
Allow non-standard HTTP methods to support payloads (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun251 authored and jeevatkm committed Feb 4, 2018
1 parent 5b61150 commit c905657
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,17 @@ func TestGetPathParams(t *testing.T) {
"userId": "[email protected]",
})
}

func TestReportMethodSupportsPayload(t *testing.T) {
ts := createGenServer(t)
defer ts.Close()

c := dc()
resp, err := c.R().
SetBody("body").
Execute("REPORT", ts.URL + "/report")

assertError(t, err)
assertEqual(t, http.StatusOK, resp.StatusCode())

}
8 changes: 8 additions & 0 deletions resty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ func createGenServer(t *testing.T) *httptest.Server {
w.WriteHeader(http.StatusOK)
return
}

if r.Method == "REPORT" && r.URL.Path == "/report" {
body, _ := ioutil.ReadAll(r.Body)
if len(body) == 0 {
w.WriteHeader(http.StatusOK)
}
return
}
})

return ts
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func getPointer(v interface{}) interface{} {
}

func isPayloadSupported(m string, allowMethodGet bool) bool {
return (m == MethodPost || m == MethodPut || m == MethodDelete || m == MethodPatch || (allowMethodGet && m == MethodGet))
return !(m == MethodHead || m == MethodOptions || (m == MethodGet && !allowMethodGet))
}

func typeOf(i interface{}) reflect.Type {
Expand Down

0 comments on commit c905657

Please sign in to comment.