diff --git a/test/parallel/test-http-response-add-header-after-sent.js b/test/parallel/test-http-response-add-header-after-sent.js new file mode 100644 index 00000000000000..4261bb61ec2957 --- /dev/null +++ b/test/parallel/test-http-response-add-header-after-sent.js @@ -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(); + }); +}); diff --git a/test/parallel/test-http-response-remove-header-after-sent.js b/test/parallel/test-http-response-remove-header-after-sent.js new file mode 100644 index 00000000000000..972ccfeb8c70cc --- /dev/null +++ b/test/parallel/test-http-response-remove-header-after-sent.js @@ -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(); + }); +});