-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: allow passing array of key/val into writeHead
Enables an optimization when the user already has the headers in an array form, e.g. when proxying. PR-URL: #35274 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
Showing
4 changed files
with
95 additions
and
4 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
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,61 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
// Verify that ServerResponse.writeHead() works with arrays. | ||
|
||
{ | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.setHeader('test', '1'); | ||
res.writeHead(200, [ 'test', '2', 'test2', '2' ]); | ||
res.end(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
http.get({ port: server.address().port }, common.mustCall((res) => { | ||
assert.strictEqual(res.headers.test, '2'); | ||
assert.strictEqual(res.headers.test2, '2'); | ||
res.resume().on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.writeHead(200, [ 'test', '1', 'test2', '2' ]); | ||
res.end(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
http.get({ port: server.address().port }, common.mustCall((res) => { | ||
assert.strictEqual(res.headers.test, '1'); | ||
assert.strictEqual(res.headers.test2, '2'); | ||
res.resume().on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
|
||
{ | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
try { | ||
res.writeHead(200, [ 'test', '1', 'test2', '2', 'asd' ]); | ||
} catch (err) { | ||
assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE'); | ||
} | ||
res.end(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
http.get({ port: server.address().port }, common.mustCall((res) => { | ||
res.resume().on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} |