Skip to content

Add appendHeader to HTTP/2 compat API and fix issues with duplicate headers in H2 writeHead

This PR

  • Adds the appendHeader method from the HTTP/1 API to the HTTP/2 compat API.
  • Fixes #51402 (closed), by using this appendHeader method to ensure that array header elements passed to writeHead don't overwrite each other. This follows the same logic as the semi-related recent fix for #50387 (closed) in HTTP/1 (so this fixes this issue, and ensures that any resulting conflicts between writeHead and setHeader are handled in the same way as HTTP/1 too).

In both cases, the specific code is drawn almost directly from the existing HTTP/1 equivalent (I've mildly tweaked the phrasing in the H1 appendHeader docs en route, as the grammar was a bit off).

There will be some performance impact to this for some uses of the H2 compat API, but I think this should be relevant only in the case where you call setHeader on a response and then also pass a separate list of headers to writeHead for that response. Performance-sensitive code should not do this, and should just pass all headers directly to writeHead in one go instead. The same concerns already apply to HTTP/1.

Merge request reports

Loading