-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
http: return Content-Length
header for HEAD
s
#56681
base: main
Are you sure you want to change the base?
Changes from 4 commits
8c4c5fc
f129867
ece7877
5051a38
6458459
0f4470f
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 |
---|---|---|
|
@@ -547,7 +547,7 @@ function _storeHeader(firstLine, headers) { | |
} | ||
|
||
if (!state.contLen && !state.te) { | ||
if (!this._hasBody) { | ||
if (!this._hasBody && this.req.method !== 'HEAD') { | ||
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. If you send a HEAD response with no body at all (e.g. because your code actually looks at the method, and skips it - not unusual I think) then what does this do? It looks like it skips the correct case (this first one), skips the next 2 ( I haven't actually tested this, but that's certainly how it looks. Either way we'll need a test for that case as it's a bit tricky - we definitely shouldn't accidentally send 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. Oh, also, if you call In both these cases, I think the issue is trying to squeeze this logic into the existing cases. This logic you want here is doable, but I think it's a bit more complicated than currently implemented here. |
||
// Make sure we don't end the 0\r\n\r\n at the end of the message. | ||
this.chunkedEncoding = false; | ||
} else if (!this.useChunkedEncodingByDefault) { | ||
|
@@ -932,7 +932,7 @@ function strictContentLength(msg) { | |
return ( | ||
msg.strictContentLength && | ||
msg._contentLength != null && | ||
msg._hasBody && | ||
(msg._hasBody || msg.req.method === 'HEAD') && | ||
!msg._removedContLen && | ||
!msg.chunkedEncoding && | ||
!msg.hasHeader('transfer-encoding') | ||
|
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.
Why this?
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.
If I'm understanding the logic correctly, the first if condition applies to those that should return neither of the
Transfer-Encoding
andContent-Length
headers. While it's true for other requests that don't have a body,HEAD
s should match the 3rd condition (i.e. the!state.trailer && !this._removedContLen && typeof this._contentLength === 'number'
one).