CrowdHailer / raxx

Interface for HTTP webservers, frameworks and clients
https://hexdocs.pm/raxx
Apache License 2.0
401 stars 29 forks source link

Should setting a body on a GET request raise an error. #142

Closed CrowdHailer closed 5 years ago

CrowdHailer commented 5 years ago

Should Raxx.set_body/2 raise an error if method is :GET?

It is not standard to send a body with a GET request, or to send a GET request with a content-length. However I have not yet been able to find anywhere in rfc7230 or rfc7540 that forbids either sending a body or setting a content-length on a get request.

HTTPoison will happily send a GET request with a content-length header, but no body. Cowboy will happily read the content-length header on the request and take the appropriate amount of body from the TCP stream.

This came up in a bug were we had a helper to add JSON to a request. in the case of no body an assumption was made that the body would be an empty map. This serializes to {} and so a content-length of two was set. But no body was sent. This surfaced as # Phoenix.Router.NoRouteError at ST /api/payment_requests\n\n(the POST request had the first two characters counted as part of previous request)

It would also be nice for cowboy or phoenix to surface that ST is an unknown method. https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#405

CrowdHailer commented 5 years ago

Yes https://tools.ietf.org/html/rfc7540#section-8.1.3

But if added to a get request manually, client and server implementations should act on it