forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missing Http2ServerResponse.setHeaders() fixed
Make it possible to invoke response.setHeaders() on response object from `node:http2` Fixes: nodejs#51573
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const body = | ||
'<html><head></head><body><h1>this is some data</h2></body></html>'; | ||
|
||
const server = http2.createServer((req, res) => { | ||
res.setHeaders(new Map([ | ||
['foobar', 'baz'], | ||
['X-POWERED-BY', 'node-test'], | ||
['connection', 'connection-test'], | ||
])); | ||
res.end(body); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const headers = { ':path': '/' }; | ||
const req = client.request(headers); | ||
req.setEncoding('utf8'); | ||
req.on('response', common.mustCall(function(headers) { | ||
assert.strictEqual(headers.foobar, 'baz'); | ||
assert.strictEqual(headers['x-powered-by'], 'node-test'); | ||
})); | ||
|
||
let data = ''; | ||
req.on('data', (d) => data += d); | ||
req.on('end', () => { | ||
assert.strictEqual(body, data); | ||
server.close(); | ||
client.close(); | ||
}); | ||
req.end(); | ||
})); | ||
|
||
const compatMsg = 'The provided connection header is not valid, ' + | ||
'the value will be dropped from the header and ' + | ||
'will never be in use.'; | ||
|
||
common.expectWarning('UnsupportedWarning', compatMsg); | ||
|
||
server.on('error', common.mustNotCall()); |
It looks like this won't properly handle
Set-Cookie
headers, which need to be passed tosetHeader()
explicitly as an array in order to work.This same bug is present in the HTTP implementation. (I am about to file that as a bug.)