From f46a04cc6d5b02d72063784175b116f7c2736256 Mon Sep 17 00:00:00 2001 From: Niklas Ingholt Date: Tue, 20 Sep 2016 15:22:16 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/8682 Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Ilkka Myller --- ...est-http-response-add-header-after-sent.js | 21 +++++++++++++++++++ ...-http-response-remove-header-after-sent.js | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/parallel/test-http-response-add-header-after-sent.js create mode 100644 test/parallel/test-http-response-remove-header-after-sent.js 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(); + }); +});