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

Set Content-Length header on DELETE, PUT when no entity body #236

Closed
katanacrimson opened this issue Jun 11, 2013 · 13 comments
Closed

Set Content-Length header on DELETE, PUT when no entity body #236

katanacrimson opened this issue Jun 11, 2013 · 13 comments

Comments

@katanacrimson
Copy link

Similar to request/request#41 - I'm seeing issues with an nginx server handling an API where DELETE operations to it are now returning HTTP 411 - there's a transfer-encoding header being injected somewhere along the way (not by superagent, likely nodejs itself because there's no content-length header) and it is causing severe problems with http requests.

@tj
Copy link
Contributor

tj commented Jul 3, 2013

hmm sounds odd to me but I guess we could

@katanacrimson
Copy link
Author

I'd appreciate that. I've had to monkey-patch it in on my own for the time being, and setting content-length to 0 for DELETE operations has managed to fix the problem. The transfer-encoding=chunked just ends up messing quite a bit up.

@defunctzombie
Copy link
Contributor

@damianb Can you provide a simple example to show the problem please.

@jdesboeufs
Copy link

Any DELETE request through nginx without body :(
Hopefully it's easy to fix with req.set('content-length', 0).

curl seems to do this by default.

@soyuka
Copy link

soyuka commented Mar 18, 2015

@defunctzombie DELETE requires a content-length, at least with nginx (seems I had no issues with apache). If I try to curl DELETE it will send a 411 Length Required status.
Solution here is to set a Content-length header:

    if(this.method == 'DELETE') {
      this.set('Content-length', 0)
    }

atm I have a hack like this one to override the Request.prototype.request method.

@defunctzombie
Copy link
Contributor

@soyuka can you make a PR with appropriate tests for this?

soyuka added a commit to soyuka/superagent that referenced this issue Jul 29, 2015
@soyuka
Copy link

soyuka commented Jul 29, 2015

@defunctzombie are there specific instructions to run tests? I did make test or make test-node but a lot is failing. Thanks.

soyuka added a commit to soyuka/superagent that referenced this issue Jul 29, 2015
soyuka added a commit to soyuka/superagent that referenced this issue Jul 29, 2015
@defunctzombie
Copy link
Contributor

@soyuka make test-node should would. For browser tests you will need to setup zuul for cloud testing. Just steps 1 & 2 should be enough.

@soyuka
Copy link

soyuka commented Jul 29, 2015

@defunctzombie sorry made a lot of mistakes in my first commit it's late here ^^.

@kornelski
Copy link
Contributor

As mentioned in #236 the HTTP RFC doesn't require DELETE request to have a Content-Length, so I think nginx is being too picky here.

Has anybody reported the issue to nginx? If the bug can be fixed in nginx I'd rather avoid adding a workaround superagent.

@katanacrimson
Copy link
Author

a client workaround will still likely be necessary due to propagation of that patch/update across the web. even if nginx patches it today, it wouldn't land anytime soon in rhel, deb, ubuntu, so handling nginx's edge case would be necessary in the meantime.

@soyuka
Copy link

soyuka commented Nov 27, 2015

@damianb I see no client workaround here. How can you set the Content-Length header from the client (aka web browser)? See in the list of forbidden header name.

@pornel agreed, but it then say in OPTIONS that a request with an empty body MUST provide a Content-Length of 0. I'll search on the nginx side if there are mention of this particular issue.

@soyuka
Copy link

soyuka commented Nov 27, 2015

Continuing the discusison from the #711 PR here:

OPTIONS:

A server MUST generate a Content-Length field with a value of "0" if no payload body is to be sent in the response.

DELETE:

A payload within a DELETE request message has no defined semantics;
sending a payload body on a DELETE request might cause some existing
implementations to reject the request.


Yes indeed, I read both, but the OPTIONS paragraph was a more logical explanation to why does nginx sends 411 when DELETE happens without Content-Length.
If you mix both parts, you could deduce that DELETE should not have any body, and so, should set the Content-Length to 0, like OPTIONS expects.

I can't find any relevent issues on the nginx Trac, I'll try to dig deeper.

Turbo87 added a commit to Turbo87/ember-cli that referenced this issue Feb 13, 2016
node v0.10.42 is rejecting DELETE requests with both Content-Length: 0 and
Transfer-Encoding: chunked headers. We can force Content-Length: 0 to work
around the problem.

see http-party/node-http-proxy#960
and ladjs/superagent#236
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

No branches or pull requests

6 participants