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

Allowing HEAD method to work with keep-alive #34231

Merged
merged 1 commit into from
Jan 3, 2021

Conversation

josephhackman
Copy link
Contributor

@josephhackman josephhackman commented Jul 6, 2020

Fixes: #28438

This approach specifically retains the non-hanging of 204 requests while allowing HEAD to function correctly with keeping sockets open. I check for 204 + 304 specifically rather than the HEAD method because the method is in _http_server, not _http_outgoing, though it could be passed along if that's preferred.

Checklist

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Jul 6, 2020
@josephhackman josephhackman changed the title Pr 1 Allowing HEAD method to work with keep-alive Jul 7, 2020
Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, thanks for doing this. Can you also test the 304 status code?

test/parallel/test-http-reuse-socket.js Outdated Show resolved Hide resolved
test/parallel/test-http-reuse-socket.js Outdated Show resolved Hide resolved
test/parallel/test-http-reuse-socket.js Outdated Show resolved Hide resolved
test/parallel/test-http-reuse-socket.js Outdated Show resolved Hide resolved
test/parallel/test-http-reuse-socket.js Outdated Show resolved Hide resolved
test/parallel/test-http-reuse-socket.js Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@josephhackman
Copy link
Contributor Author

It seems that the only tests failing are flakey. Is there additional action required on my part?

@bnoordhuis
Copy link
Member

@josephhackman No action on your part is needed but since this is a fairly subtle change it'd be good to get at least one more sign-off from a @nodejs/http member.

josephhackman added a commit to josephhackman/node that referenced this pull request Aug 3, 2020
Re-factoring to address PR comment. The logic here gets somewhat
complicated with regards to the if-elseif block circa line 434.
The goal of this PR is to prevent head requests from having their
Content-Length or Content-Encoding headers cleared except when
necessary, which is when the response code is 204 or 304. In trying
to address comment, I'm balancing between a larger re-factor than
absolutely needed and somewhat ugly control logic.

Refs: nodejs#34231 (comment)
@josephhackman josephhackman requested a review from a team as a code owner August 10, 2020 16:06
@ronag
Copy link
Member

ronag commented Aug 10, 2020

Just as a side note. HEAD requests have an edge case due to which many HTTP clients (including the node one) will always close the connection and ignore keep-alive.

#12396
nodejs/undici#258

@josephhackman
Copy link
Contributor Author

Just as a side note. HEAD requests have an edge case due to which many HTTP clients (including the node one) will always close the connection and ignore keep-alive.

#12396
mcollina/undici#258

This isn't quite true. The node client will close a the connection on a HEAD response if neither the Content-Length or Content-Encoding headers are set. This PR contains a test that empirically verifies this, using the node server and client. This PR does not make any changes to the node client, so it will continue doing what it did before, which is sometimes closing the socket on head-requests.

These headers are allowed by the HTTP standard, so this change should keep the node server just as compliant as it always was, while allowing any properly-implemented client to be substantially faster while sending many HEAD requests to collect metadata.

On the other hand, it is possible that non-standards-compliant clients exist that would malfunction seeing these headers on a HEAD request. I think that's a minimal risk because most people don't implement their own HTTP client library, but many people do mess with the headers on their servers. This leads me to expect that clients tend to be standards-compliant, and if anything, hardened.

Refs: https://tools.ietf.org/html/rfc7231#section-3.3
Refs: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

@trivikr trivikr requested a review from jasnell September 11, 2020 05:44
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 17, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 17, 2020
@nodejs-github-bot
Copy link
Collaborator

@ronag
Copy link
Member

ronag commented Dec 27, 2020

This needs another approval. I'm not comfortable in my own knowledge here to give the second one.

@nodejs/http

@ronag ronag added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 27, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 27, 2020
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 3, 2021
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 3, 2021
@nodejs-github-bot
Copy link
Collaborator

Fixes: nodejs#28438

PR-URL: nodejs#34231
Reviewed-By: James M Snell <jasnell@gmail.com>
@aduh95
Copy link
Contributor

aduh95 commented Jan 3, 2021

Landed in 7afa533 🎉 Thanks a lot for your contribution!

@aduh95 aduh95 merged commit 7afa533 into nodejs:master Jan 3, 2021
danielleadams pushed a commit that referenced this pull request Jan 12, 2021
Fixes: #28438

PR-URL: #34231
Reviewed-By: James M Snell <jasnell@gmail.com>
@danielleadams danielleadams mentioned this pull request Jan 12, 2021
targos pushed a commit that referenced this pull request May 1, 2021
Fixes: #28438

PR-URL: #34231
Reviewed-By: James M Snell <jasnell@gmail.com>
@danielleadams danielleadams mentioned this pull request May 3, 2021
@fluggo
Copy link

fluggo commented May 18, 2021

I'm not convinced this was a good change. My HEAD methods with status 200 now send content-length: 0 by default, and this is very much not allowed by RFC7230:

A server MAY send a Content-Length header field in a response to a
HEAD request (Section 4.3.2 of [RFC7231]); a server MUST NOT send
Content-Length in such a response unless its field-value equals the
decimal number of octets that would have been sent in the payload
body of a response if the same request had used the GET method.

Seems to me the sensible default would have been transfer-encoding: chunked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http server respond with inappropriate default headers for HEAD method
8 participants