-
-
Notifications
You must be signed in to change notification settings - Fork 30
Handle OPTIONS content-length #83
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ const { | |
filterPseudoHeaders, | ||
copyHeaders, | ||
stripHttp1ConnectionHeaders, | ||
filterHeaders, | ||
buildURL | ||
} = require('./lib/utils') | ||
|
||
|
@@ -53,11 +52,11 @@ function fastProxy (opts = {}) { | |
|
||
let body = null | ||
// according to https://tools.ietf.org/html/rfc2616#section-4.3 | ||
// proxy should ignore message body when it's a GET or HEAD request | ||
// proxy should ignore message body when it's a GET, HEAD or OPTIONS request | ||
// when proxy this request, we should reset the content-length to make it a valid http request | ||
if (req.method === 'GET' || req.method === 'HEAD') { | ||
if (headers['content-length']) { | ||
headers = filterHeaders(headers, 'content-length') | ||
if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') { | ||
if (headers.hasOwnProperty('content-length')) { | ||
delete headers['content-length'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using filterHeaders has maybe some deeper reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the context when it was introduced #38 (for the same undici reason I raised about OPTIONS) -We could think it was made that way to prevent object mutation but headers are taken from a spread, so no risks of modifying elsewhere, and
- Are you ok with delete then ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete is usually slower than just creating a new Object. |
||
} | ||
} else { | ||
if (req.body) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. If you want to use hasOwnProperty, than do it with
Object.prototype.hasOwnProperty.call(headers, 'content-length')
But imho the better way is
'content-length' in headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, safer and better to use
in