node/test/parallel/test-http-outgoing-internal-headers.js
Anatoli Papirovski 602ffd6986
http: refactor outgoing headers processing
Use a shared function, for..in instead of Object.keys, do less work in
`setHeader` and instead defer some of it until later, and other minor
changes to improve clarity, as well as a slight boost in performance.

PR-URL: https://github.com/nodejs/node/pull/20250
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-27 20:31:25 +02:00

31 lines
745 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const { outHeadersKey } = require('internal/http');
const { OutgoingMessage } = require('http');
{
// tests for _headers get method
const outgoingMessage = new OutgoingMessage();
outgoingMessage.getHeaders = common.mustCall();
outgoingMessage._headers;
}
{
// tests for _headers set method
const outgoingMessage = new OutgoingMessage();
outgoingMessage._headers = {
host: 'risingstack.com',
Origin: 'localhost'
};
assert.deepStrictEqual(
Object.entries(outgoingMessage[outHeadersKey]),
Object.entries({
host: ['host', 'risingstack.com'],
origin: ['Origin', 'localhost']
}));
}