Skip to content

Http2 reverses order of headers starting with ":" prefix #38797

@blakebyrnes

Description

@blakebyrnes
  • Version: 14.x, 15.x
  • Platform: Darwin Kernel Version 18.7.0: Mon Mar 8 22:11:48 PST 2021; root:xnu-4903.278.65~1/RELEASE_X86_64 x86_64
  • Subsystem:

What steps will reproduce the bug?

  const server = http2
    .createSecureServer(sslCerts(), (req, res) => {
      const headerOrder = req.rawHeaders.map((x, i) => {
        if (i % 2 === 0) return x;
        return undefined;
      });
      // expect headerOrder to be sent order, but will be [':path:',':scheme',':authority',:'method', 'accept-encoding','accept-language']
    })
    .unref()
    .listen(1664);

  const client = http2.connect(`https://localhost:1664`);

  const headers = {
    ':method': 'GET',
    ':authority': `localhost:1664`,
    ':scheme': 'https',
    ':path': '/temp1',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9',
  };
  const h2stream = client.request(headers);

How often does it reproduce? Is there a required condition?

Everytime

What is the expected behavior?

Header order matching provided headers

What do you see instead?

Headers are reversed

Additional information

NodeJs is following the spec to insert special http2 headers in the front of the list, but since it traverses headers in order and prepends each one, the prefixed headers will be reversed:

ret = `${key}\0${value}\0${flags}${ret}`;

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions