Skip to content
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

Transfer-Encoding: chunked request fails with 411 Length Required #94

Closed
javabrett opened this issue Feb 19, 2018 · 0 comments · Fixed by #95
Closed

Transfer-Encoding: chunked request fails with 411 Length Required #94

javabrett opened this issue Feb 19, 2018 · 0 comments · Fixed by #95

Comments

@javabrett
Copy link
Contributor

This was noticed during some deployment-testing of httpbin issue https://github.com/kennethreitz/httpbin/issues/340 . In that issue it is noted that having fixed some issues with the Gunicorn deployment, a different problem with chunked requests now occurs, but only when --worker-class="egg:meinheld#gunicorn_worker" is used, which is how httpbin is currently-deployed to https://httpbin.org .

Test request/response:

$ curl -v -X POST http://httpbin.org/post -d '{"message":"BLA"}'  -H 'Content-Type: application/json'  -H 'Transfer-Encoding: chunked'
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 54.225.130.23...
* TCP_NODELAY set
* Connected to httpbin.org (54.225.130.23) port 80 (#0)
> POST /post HTTP/1.1
> Host: httpbin.org
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Transfer-Encoding: chunked
>
> 11
* upload completely sent off: 24 out of 17 bytes
< HTTP/1.1 411 Length Required
< Date: Mon, 19 Feb 2018 22:23:59 GMT
< Connection: close
< Content-Type: text/html
< Server: meinheld/0.6.1
< Via: 1.1 vegur
<
* Closing connection 0
<html><head><title>Length Required</title></head><body><p>Length Required.</p></body></html>

Actual traffic on wire:

POST /post HTTP/1.1
Host: httpbin.org
User-Agent: curl/7.54.0
Accept: */*
Content-Type: application/json
Transfer-Encoding: chunked

11
{"message":"BLA"}
0

HTTP/1.1 411 Length Required
Date: Mon, 19 Feb 2018 22:23:59 GMT
Connection: close
Content-Type: text/html
Server: meinheld/0.6.1
Via: 1.1 vegur

<html><head><title>Length Required</title></head><body><p>Length Required.</p></body></html>

The same result can be generated using a local Docker running with --worker-class="egg:meinheld#gunicorn_worker". Without the meinheld worker the request succeeds and the chunked request-data is echoed-back.

The 411 error is set by https://github.com/mopemope/meinheld/blob/master/meinheld/server/http_request_parser.c#L616 , where the criteria is req->body_type == BODY_TYPE_NONE and req->body_length == 0. I can only assume that the latter occurs if there is no Content-Length header, which is correct for a chunked-request.

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 a pull request may close this issue.

1 participant