From f5bea638dfeb02cdf47648ce2833353cbc424576 Mon Sep 17 00:00:00 2001 From: Peter Czibik Date: Thu, 29 Jun 2017 10:30:44 +0200 Subject: [PATCH] test: http outgoing _renderHeaders PR-URL: https://github.com/nodejs/node/pull/13981 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- .../test-http-outgoing-renderHeaders.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/parallel/test-http-outgoing-renderHeaders.js diff --git a/test/parallel/test-http-outgoing-renderHeaders.js b/test/parallel/test-http-outgoing-renderHeaders.js new file mode 100644 index 00000000000000..bae7fc58120593 --- /dev/null +++ b/test/parallel/test-http-outgoing-renderHeaders.js @@ -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' + }); +}