Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add an exception test to http-write-head #11034

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions test/parallel/test-http-write-head.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const http = require('http');

// Verify that ServerResponse.writeHead() works as setHeader.
// Issue 5036 on github.

const s = http.createServer(function(req, res) {
const s = http.createServer(common.mustCall((req, res) => {
res.setHeader('test', '1');

// toLowerCase() is used on the name argument, so it must be a string.
Expand All @@ -32,18 +32,23 @@ const s = http.createServer(function(req, res) {
assert.ok(threw, 'Undefined value should throw');

res.writeHead(200, { Test: '2' });

assert.throws(() => {
res.writeHead(100, {});
}, /^Error: Can't render headers after they are sent to the client$/);

res.end();
});
}));

s.listen(0, runTest);
s.listen(0, common.mustCall(runTest));

function runTest() {
http.get({ port: this.address().port }, function(response) {
response.on('end', function() {
http.get({ port: this.address().port }, common.mustCall((response) => {
response.on('end', common.mustCall(() => {
assert.strictEqual(response.headers['test'], '2');
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
s.close();
});
}));
response.resume();
});
}));
}