Skip to content

Read GET/HEAD body if it exists #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

oschwald
Copy link

@oschwald oschwald commented Sep 14, 2016

Previously, GET/HEAD bodies were not read. The HTTP 1.1 specification
states:

"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.
I suspect this code is at fault."

This change reads the body on such request and continues the previous
behavior of returning a "Content-Length" of 0 to the application.

Closes #159.

@oschwald
Copy link
Author

I would be happy to modify this to completely discard the body as well if that is the preferred behavior. That might be more in line with the spec. Just let me know.

@valyala
Copy link
Owner

valyala commented Oct 5, 2016

What is the use case for this feature?
Which clients allow sending bodies in GET or HEAD requests?

@oschwald
Copy link
Author

oschwald commented Oct 5, 2016

Unfortunately, there are quite a few real world GET requests that have a
body. Many clients allow this. Currently, fasthttp incorrectly drops the
connection and logs an error. This PR brings fasthttp in line with net/http
and the HTTP/1.1 spec. As I mentioned, I would be happy to modify the PR to
discard the body rather than putting it in the buffer.

On Wed, Oct 5, 2016, 3:23 AM Aliaksandr Valialkin [email protected]
wrote:

What is the use case for this feature?
Which clients allow sending bodies in GET or HEAD requests?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#171 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AARBM75WGJcrulK-Y1REgjCOuv-FE50Oks5qw3q1gaJpZM4J9Uhu
.

@ghost
Copy link

ghost commented Oct 5, 2016

You can send a body with GET, but it's never useful to do so.

This is part of the layered design of HTTP/1.1 will become clear again once the spec is partitioned, future changes may discard this option

@oschwald
Copy link
Author

oschwald commented Oct 5, 2016

I agree it is not useful to send a body. The intent of this PR is not to
make the body useful. It is to stop fasthttp from dropping the connection
prematurely and logging an error.

On Wed, Oct 5, 2016, 4:42 AM Gerasimos Maropoulos [email protected]
wrote:

You can send a body with GET, but it's never useful to do so.

This is part of the layered design of HTTP/1.1 will become clear again
once the spec is partitioned, future changes may discard this option


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#171 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AARBMzIZ7prfO2Md7BYrGvI6oViwPp-7ks5qw40tgaJpZM4J9Uhu
.

Previously, GET/HEAD bodies were not read. The HTTP 1.1 specification
states:

"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.
I suspect this code is at fault."

This change reads the body on such request and continues the previous
behavior of returning a "Content-Length" of 0 to the application.

Closes valyala#159.
@oschwald oschwald force-pushed the greg/read-get-head-body branch from 9e4b4b5 to 13d5893 Compare October 9, 2016 18:54
@oschwald
Copy link
Author

An alternative to this PR would be to return a 4xx error on GET requests with a body. net/http might switch to that behavior in the future, golang/go#13722. This would be more inconvenient for me personally (as we have clients sending us this stuff), but it would be an improvement over the current behavior where the connection hangs until it times out.

@docmerlin
Copy link

We are also having this same problem. We are losing connections due to this bug.

@docmerlin
Copy link

'What is the use case for this feature?
Which clients allow sending bodies in GET or HEAD requests?'

  • several.

Furthermore, it violates the robustness principle to not accept such requests.
"be liberal in what you accept, and conservative in what you send"

@docmerlin
Copy link

Almost all our requests to this service come from JS on browsers, and we are missing quite a few due to this bug. Please accept a patch.

@theiostream
Copy link

Please accept this patch.

1 similar comment
@hails
Copy link

hails commented Mar 15, 2017

Please accept this patch.

@filipedeschamps
Copy link

I also need this feature!

@greenboxal
Copy link

+1
Although it's not in official spec, this makes sense nowadays to some payloads. A good example is an Elasticsearch query which makes more sense as a GET as I'm searching for something but it has a really long payload that doesn't fit well in the query string.

@erikdubbelboer
Copy link
Collaborator

I merged the pull request into my branch which contains other important fixes such as erikdubbelboer@28a6163 as well.

@oschwald
Copy link
Author

oschwald commented Aug 1, 2017

Thanks, @erikdubbelboer! I've switched to using your fork.

@tsingson
Copy link

thanks for the patch .

@erikdubbelboer
Copy link
Collaborator

Was fixed in cf6f6e7

@oschwald
Copy link
Author

Thanks! I'll close this.

@oschwald oschwald closed this Aug 26, 2018
@oschwald oschwald deleted the greg/read-get-head-body branch August 26, 2018 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants