Skip to content

Commit

Permalink
test: http outgoing _renderHeaders
Browse files Browse the repository at this point in the history
PR-URL: nodejs#13981
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
peteyycz authored and refack committed Jul 14, 2017
1 parent 2288e3f commit 074b7c2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/parallel/test-http-outgoing-renderHeaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';
// Flags: --expose-internals

require('../common');
const assert = require('assert');

const outHeadersKey = require('internal/http').outHeadersKey;
const http = require('http');
const OutgoingMessage = http.OutgoingMessage;

{
const outgoingMessage = new OutgoingMessage();
outgoingMessage._header = {};
assert.throws(
outgoingMessage._renderHeaders.bind(outgoingMessage),
/^Error: Can't render headers after they are sent to the client$/
);
}

{
const outgoingMessage = new OutgoingMessage();
outgoingMessage[outHeadersKey] = null;
const result = outgoingMessage._renderHeaders();
assert.deepStrictEqual(result, {});
}


{
const outgoingMessage = new OutgoingMessage();
outgoingMessage[outHeadersKey] = {};
const result = outgoingMessage._renderHeaders();
assert.deepStrictEqual(result, {});
}

{
const outgoingMessage = new OutgoingMessage();
outgoingMessage[outHeadersKey] = {
host: ['host', 'nodejs.org'],
origin: ['Origin', 'localhost']
};
const result = outgoingMessage._renderHeaders();
assert.deepStrictEqual(result, {
host: 'nodejs.org',
Origin: 'localhost'
});
}

0 comments on commit 074b7c2

Please sign in to comment.