Why Is My Custom Header Missing When Chrome Uses HTTP/2?

0
2
Asked By MistyHarbor42 On

I'm controlling Chrome with Puppeteer and need to send a custom `proxyserver` header to certain hosts. It works reliably with HTTP/1.1 servers, but HTTPS targets using HTTP/2 appear to receive something like `: ` instead—the header name seems to have been stripped. Other headers are present, and this behavior is visible in Chrome NetLog output. I'm setting the header with `page.setExtraHTTPHeaders`. Is this expected behavior for custom headers over HTTP/2, or could it be a logging or display issue? I'd appreciate an explanation based on the HTTP/2 specification or Chrome's implementation.

2 Answers

Answered By QuietPine7 On

HTTP/2 does allow ordinary custom headers, so a name such as `proxyserver` should not be rejected merely because it is custom. HTTP/2 does have special pseudo-header fields whose names begin with `:`, such as `:method` and `:authority`, but a normal header must still have a nonempty name. If the raw HTTP/2 stream really contains a header with an empty name, the peer should treat that as a protocol error. It’s worth checking the decoded wire data rather than relying only on a UI or log representation that may be displaying HTTP/2 headers in an HTTP/1-style format.

MistyHarbor42 -

We checked Chrome NetLog JSON rather than just a browser display. The other HTTP/2 headers are shown with their expected colon-prefixed pseudo-header names, while this custom header appears to lose its name.

Answered By CopperLynx19 On

`page.setExtraHTTPHeaders` is normally translated into regular request headers; it shouldn’t convert arbitrary names into HTTP/2 pseudo-headers. Compare the request before protocol negotiation and inspect the server’s HTTP/2 decoding or proxy layer as well. A proxy, header normalization rule, or Chrome/Chromium bug could be removing the name, while the NetLog entry may simply be exposing an internal header representation. Calling the underlying DevTools `Network.setExtraHTTPHeaders` directly could be a useful comparison, but custom headers themselves are not prohibited by HTTP/2.

MistyHarbor42 -

We’re currently using `page.setExtraHTTPHeaders`; testing the DevTools Protocol call directly may help determine whether Puppeteer’s wrapper changes anything.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.