-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: enable call chaining with setHeader()
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: #33148 PR-URL: #35924 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
1 parent
2677fe9
commit ad39b37
Showing
3 changed files
with
35 additions
and
1 deletion.
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,29 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
const assert = require('assert'); | ||
const expected = { | ||
'__proto__': null, | ||
'testheader1': 'foo', | ||
'testheader2': 'bar', | ||
'testheader3': 'xyz' | ||
}; | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
let retval = res.setHeader('testheader1', 'foo'); | ||
|
||
// Test that the setHeader returns the same response object. | ||
assert.strictEqual(retval, res); | ||
|
||
retval = res.setHeader('testheader2', 'bar').setHeader('testheader3', 'xyz'); | ||
// Test that chaining works for setHeader. | ||
assert.deepStrictEqual(res.getHeaders(), expected); | ||
res.end('ok'); | ||
})); | ||
server.listen(0, () => { | ||
http.get({ port: server.address().port }, common.mustCall((res) => { | ||
res.on('data', () => {}); | ||
res.on('end', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
}); |