Created by: jugglinmike
Note also that this change was previously suggested as part of the resolution of https://github.com/nodejitsu/node-http-proxy/pull/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 aLength
header. This makes proxied OPTIONS requests from web browsers invalid.Explicitly set the
Content-Length
header of allOPTIONS
requests to "0", disabling the default "chunked" encoding behavior [2].[1] http://www.w3.org/TR/cors/ [2] http://nodejs.org/api/http.html