-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
http: add writeEarlyHints function to ServerResponse #44180
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: add writeEarlyHints function to ServerResponse #44180
Conversation
|
Review requested:
|
9c87898 to
3c6b924
Compare
mcollina
left a comment
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.
lgtm, solid work. It seems Chrome supports them now:
https://developer.chrome.com/blog/early-hints/
Could you add them to HTTP/2 too? Or it would be better to do it in a follow-up PR?
ShogunPanda
left a comment
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.
LGTM!
@mcollina good idea! I'll have to look into the http2 implementation first, I haven't read up on how the stream internals work exactly, first thought is to add it here but I'm not sure yet how it would work in a stream. Will have another look |
mcollina
left a comment
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.
What should happen if the array is empty? Could you add a test for this case?
|
Also what should happen when neither a string nor array is passed in? Is a 103 without headers permitted? Should we throw an exception? Either way we should also add tests for other value types. |
@mscdex I added an else clause that will throw an wdyt? |
@mcollina I think there will be scenarios where we want to create a As opposed to invalid types like objects (what @mscdex mentioned ☝️ ), I think that's more of a programmatic error so in that case I'm throwing wdyt? Added test cases |
|
minor nit: perhaps we could consolidate the tests into one file for this new feature? Additionally we should test that the function throws when it should. |
mcollina
left a comment
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.
lgtm
@mscdex because the invalid argument test throws an exception where I |
LiviaMedeiros
left a comment
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.
The first commit in PR should start with affected sybsystem, which is http (src mostly refers to generic changes in C++ parts of code). This can be fixed by rebasing and force-pushing, or on landing stage.
|
This PR must be backported / released together with #44820. cc @nodejs/releasers |
Similar to the
writeContinueandwriteProcessingfunctions, we could introduce awriteEarlyHintsfunction where we could write the early hints response in a slightly friendlier waywould become
Problem: multiple headers
_writeRaw()cannot be used with multiple headers so I folded the headers into one line.an alternative way to write this is the following
however, this also folds into a oneliner, so I think prefolding it before calling
_writeRaw()just once was better.The problem is these folded headers may work now but could become deprecated in future http releases. So maybe I should just write
_writeRaw()multiple times and look into unfolding or prevent the folding of the sent header elsewhere 🤔thoughts?
Resources
obs-fold👉 https://www.ietf.org/rfc/rfc7230.html