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 for OPTIONS requests #742

Merged
merged 1 commit into from
Nov 25, 2014

Conversation

jugglinmike
Copy link
Contributor

Note also that this change was previously suggested as part of the resolution of #338, but it never made it to master.

I'm not so happy about special-casing individual HTTP verbs like this, and I doubt the maintainers are, either. A better solution would involve disabling the default Node.js behavior described in the commit message (below). That behavior might make sense to make the http and https modules more usable, but in the setting of an HTTP proxy, fidelity is much more important.

This seems possible via the useChunkedEncodingByDefault attribute, but that is undocumented and likely unstable. I wasn't able to get it working locally, likely because this library uses pipe for all "incoming" requests. When piping data, the useChunkedEncodingByDefault flag does not seem to be honored. This probably makes sense because a streaming interface would generally emit data in chunks... so maybe special-casing HTTP verbs is the best approach, after all.

Commit message:

Web browsers automatically issue an OPTIONS request in advance of other
HTTP requests when the document's domain does not match the target in
order to facilitate Cross-Origin Resource Sharing. These requests are
forbidden from specifying a body and typically do not specify an
(unecessary) Length header.

Node.js automatically adds the Content-Encoding: chunked header value
to requests that do not specify a Length header. This makes proxied
OPTIONS requests from web browsers invalid.

Explicitly set the Content-Length header of all OPTIONS requests to
"0", disabling the default "chunked" encoding behavior [2].

[1] http:https://www.w3.org/TR/cors/
[2] http:https://nodejs.org/api/http.html

Web browsers automatically issue an OPTIONS request in advance of other
HTTP requests when the document's domain does not match the target in
order to facilitate Cross-Origin Resource Sharing. These requests are
forbidden from specifying a body and typically do not specify an
(unecessary) `Length` header.

Node.js automatically adds the `Content-Encoding: chunked` header value
to requests that do not specify a `Length` header. This makes proxied
OPTIONS requests from web browsers invalid.

Explicitly set the `Content-Length` header of all `OPTIONS` requests to
"0", disabling the default "chunked" encoding behavior [2].

[1] http:https://www.w3.org/TR/cors/
[2] http:https://nodejs.org/api/http.html
@samccone
Copy link
Contributor

👍 lgtm

jcrugzz added a commit that referenced this pull request Nov 25, 2014
Set `Content-Length` header for OPTIONS requests
@jcrugzz jcrugzz merged commit 3194d81 into http-party:master Nov 25, 2014
@jcrugzz
Copy link
Contributor

jcrugzz commented Nov 25, 2014

Thanks!

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.

None yet

3 participants