Skip to content
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/2 compat API drops duplicate headers when raw headers are provided #51402

Closed
pimterry opened this issue Jan 8, 2024 · 0 comments · Fixed by #51412
Closed

HTTP/2 compat API drops duplicate headers when raw headers are provided #51402

pimterry opened this issue Jan 8, 2024 · 0 comments · Fixed by #51412

Comments

@pimterry
Copy link
Member

pimterry commented Jan 8, 2024

Version

v21.4.0, v20.8.0

Platform

Linux 6.2.0-39-generic 40-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 14 14:18:00 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

http2

What steps will reproduce the bug?

const http2 = require('http2');

const server = http2.createServer((req, res) => {
    console.log('Got request');

    // This would work as expected:
    // res.writeHead(200, {
    //     'set-cookie': ['a', 'b']
    // });

    // This does not:
    res.writeHead(200, [
        'set-cookie', 'a',
        'set-cookie', 'b'
    ]);
    res.end('Done');
});

server.listen(9000, () => {
    const client = http2.connect(`http://localhost:${server.address().port}`);
    const req = client.request({ ':path': '/' });
    req.on('response', (res) => {
        console.log('Got response', res);
    });
});

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

Every time

What is the expected behavior? Why is that the expected behavior?

The response should show two set-cookie values

What do you see instead?

The response shows only the 2nd value, losing the first:

$ node test.js
Got request
Got response [Object: null prototype] {
  ':status': 200,
  'set-cookie': [ 'b' ],
  date: 'Mon, 08 Jan 2024 15:31:54 GMT',
  [Symbol(nodejs.http2.sensitiveHeaders)]: []
}

Additional information

This is part of the HTTP/1 compat API for HTTP/2. This works correctly with HTTP/1, but here although the compat layer attempts to handle raw headers, it doesn't quite do so correctly for trickier cases like this. It seems that the logic used in the compat API in #42901 (a fix for a different compat API issue) didn't take duplicate headers into account, and so the last matching header overrides all others.

I'll open up a fix for this shortly, watch this space.

@pimterry pimterry changed the title HTTP/2 compat API drops duplicate headers with raw headers are provided HTTP/2 compat API drops duplicate headers when raw headers are provided Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant