-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
http2: add raw header array support to h2Session.request() #57917
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
Conversation
This also notably changes error handling for request(). Previously some invalid header values (but not all) would cause the session to be unnecessarily destroyed automatically, e.g. passing an unparseable header name to request(). This is no longer the case: header validation failures will throw an error, but will not destroy the session or emit 'error' events.
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57917 +/- ##
==========================================
- Coverage 90.25% 90.24% -0.01%
==========================================
Files 630 630
Lines 185880 186072 +192
Branches 36434 36461 +27
==========================================
+ Hits 167757 167921 +164
- Misses 11010 11034 +24
- Partials 7113 7117 +4
🚀 New features to boost your workflow:
|
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
This has a passing CI & one approval, and it's been open for more than 7 days, so it's now mergable! It is a bit fiddly & sensitive, and I want to check for any disagreement before I open more PRs like this for the other header API methods, so I'll leave it a few more days in case anybody else in @nodejs/http2 has opinions - if not, I'll land it sometime next week. |
This also notably changes error handling for request(). Previously some invalid header values (but not all) would cause the session to be unnecessarily destroyed automatically, e.g. passing an unparseable header name to request(). This is no longer the case: header validation failures will throw an error, but will not destroy the session or emit 'error' events. PR-URL: #57917 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 4cd8e19 |
This also notably changes error handling for request(). Previously some invalid header values (but not all) would cause the session to be unnecessarily destroyed automatically, e.g. passing an unparseable header name to request(). This is no longer the case: header validation failures will throw an error, but will not destroy the session or emit 'error' events. PR-URL: #57917 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This change allows you to call
h2Session.request(['k1', 'v1', 'k2', 'v2'])
, just like in the HTTP/1 APIs.Raw header support like this is useful for intermediaries, who generally already have headers in raw format already and would really like to preserve them exactly as received (without any unnecessary reordering or duplicate handling), and for anybody would wants to avoid the effort/perf to objectify headers unnecessarily.
I've added this just to
request()
for now, but I'd like to add support in the various other HTTP/2 methods - this is a first step to discuss any debatable points here up front.There's a few notable details in here:
request()
would destroy the entire underlying session with an error (and would not throw an error)). Not all though - e.g. keyheader::name
would destroy the session with an error, but:unknown-pseudo-header
, multiple:method
headers or setting HTTP/2-invalid connection/keep-alive/etc headers would throw (all without destroying the session - just failing to create a new stream). AFAICT there is no good reason for this, and it's very awkward & surprising behaviour. I've removed it, and the parts of the tests (test/parallel/test-http2-invalidheaderfield.js) which checked it - this is arguably a breaking change in error handling, let me know what you think.stream[kSentHeaders]
, used byrequest.sentHeaders
. That means that property remains undefined - this matches the behaviour of other APIs likehttp.request
, which doesn't setkOutHeaders
for HTTP/1.1 if you pass raw headers. That avoids some work and keeps things consistent, but it's a bit ugly. Opinions welcome - we could easily lazily instantiatesentHeaders
instead to avoid any perf hit on the fast path anyway. We could even consider changing HTTP/1.1 to do the same!request()
- that's because I think the same checks are all run again afterwards withinbuildNgHeaderString
(previously calledmapToHeaders
) so I'm fairly sure this was adding nothing.