-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for add/remove header after sent
This change adds tests to make sure an Error is thrown if a header is added or removed after they are sent. PR-URL: #8682 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ilkka Myller <[email protected]>
- Loading branch information
1 parent
e79351c
commit f46a04c
Showing
2 changed files
with
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer((req, res) => { | ||
assert.doesNotThrow(() => { | ||
res.setHeader('header1', 1); | ||
}); | ||
res.write('abc'); | ||
assert.throws(() => { | ||
res.setHeader('header2', 2); | ||
}, /Can't set headers after they are sent\./); | ||
res.end(); | ||
}); | ||
|
||
server.listen(0, () => { | ||
http.get({port: server.address().port}, () => { | ||
server.close(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/parallel/test-http-response-remove-header-after-sent.js
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,21 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer((req, res) => { | ||
assert.doesNotThrow(() => { | ||
res.removeHeader('header1', 1); | ||
}); | ||
res.write('abc'); | ||
assert.throws(() => { | ||
res.removeHeader('header2', 2); | ||
}, /Can't remove headers after they are sent/); | ||
res.end(); | ||
}); | ||
|
||
server.listen(0, () => { | ||
http.get({port: server.address().port}, () => { | ||
server.close(); | ||
}); | ||
}); |