From ed625fefd24013b04d2b49db4ea4f4575669cb46 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 0000000000..4261bb61ec --- /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 0000000000..972ccfeb8c --- /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(); + }); +});