Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

GET request have a non-zero content length #11

Open
stephanenicolas opened this issue Jul 19, 2013 · 3 comments
Open

GET request have a non-zero content length #11

stephanenicolas opened this issue Jul 19, 2013 · 3 comments

Comments

@stephanenicolas
Copy link
Contributor

GET Requests sent by the rest template contain a non-zero content-length header.
This doesn't affect much of the most common webservers, but, as this violates http recommandations, some servers are impacted and can't handle the requests properly.

It happens, for instance, but that it not the only one for sure : with mock webserver, a server dedicated for testing http requests inside android or java projects) :
https://code.google.com/p/mockwebserver/issues/detail?id=9&can=1&q=content#makechanges

The specifications of HTTP are clear : (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html section 4.3 and 4.4)

The presence of a message-body in a request is signaled by the inclusion of a
Content-Length or Transfer-Encoding header field in the request's message-headers. A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests. A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.

@josephearl
Copy link

Actually, there is nothing in the specification that says GET requests cannot have a body -- see section 9.x.
So it may be inadvisable, but not illegal.

@stephanenicolas
Copy link
Contributor Author

I agree that it is not explicitly forbidden, but Spring Android should embrace the Robustness principle and not rely on the fact that servers, if they are coded in a laxist enough way, may accept its requests.

This link has a quite good argument for it : http://stackoverflow.com/questions/978061/http-get-with-request-body

And, as it breaks some servers already, I think we should really not send neither bodies nor content-length headers in GET requests.

Is that a lot of work to correct it ?

@loicsiret
Copy link

Hi,
I'm facing the same problem, when I do get request all of them got à Header Content-length equals to 0. And are badly interpreted by server. Does à fix exist for this ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants