Skip to content
Permalink
Browse files

http: follow symbol naming convention

PR-URL: #29091
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
ronag authored and targos committed Aug 12, 2019
1 parent 0aa339e commit 6b9e372198f045e9fd558a398cbb3da240e4f872
@@ -40,7 +40,7 @@ const Agent = require('_http_agent');
const { Buffer } = require('buffer');
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
const { outHeadersKey, ondrain } = require('internal/http');
const { kOutHeaders, ondrain } = require('internal/http');
const { connResetException, codes } = require('internal/errors');
const {
ERR_HTTP_HEADERS_SENT,
@@ -253,7 +253,7 @@ function ClientRequest(input, options, cb) {
}

this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
this[outHeadersKey]);
this[kOutHeaders]);
}
} else {
this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
@@ -308,7 +308,7 @@ ClientRequest.prototype._implicitHeader = function _implicitHeader() {
throw new ERR_HTTP_HEADERS_SENT('render');
}
this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
this[outHeadersKey]);
this[kOutHeaders]);
};

ClientRequest.prototype.abort = function abort() {
@@ -27,7 +27,7 @@ const { getDefaultHighWaterMark } = require('internal/streams/state');
const assert = require('internal/assert');
const Stream = require('stream');
const internalUtil = require('internal/util');
const { outHeadersKey, utcDate } = require('internal/http');
const { kOutHeaders, utcDate } = require('internal/http');
const { Buffer } = require('buffer');
const common = require('_http_common');
const checkIsHttpToken = common._checkIsHttpToken;
@@ -104,7 +104,7 @@ function OutgoingMessage() {
this.socket = null;
this.connection = null;
this._header = null;
this[outHeadersKey] = null;
this[kOutHeaders] = null;

this._onPendingData = noopPendingOutput;
}
@@ -145,9 +145,9 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'),
set: internalUtil.deprecate(function(val) {
if (val == null) {
this[outHeadersKey] = null;
this[kOutHeaders] = null;
} else if (typeof val === 'object') {
const headers = this[outHeadersKey] = Object.create(null);
const headers = this[kOutHeaders] = Object.create(null);
const keys = Object.keys(val);
for (var i = 0; i < keys.length; ++i) {
const name = keys[i];
@@ -159,7 +159,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {

Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
get: internalUtil.deprecate(function() {
const headers = this[outHeadersKey];
const headers = this[kOutHeaders];
if (headers !== null) {
const out = Object.create(null);
const keys = Object.keys(headers);
@@ -174,7 +174,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
}, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066'),
set: internalUtil.deprecate(function(val) {
if (typeof val === 'object' && val !== null) {
const headers = this[outHeadersKey];
const headers = this[kOutHeaders];
if (!headers)
return;
const keys = Object.keys(val);
@@ -193,7 +193,7 @@ OutgoingMessage.prototype._renderHeaders = function _renderHeaders() {
throw new ERR_HTTP_HEADERS_SENT('render');
}

const headersMap = this[outHeadersKey];
const headersMap = this[kOutHeaders];
const headers = {};

if (headersMap !== null) {
@@ -316,7 +316,7 @@ function _storeHeader(firstLine, headers) {
};

if (headers) {
if (headers === this[outHeadersKey]) {
if (headers === this[kOutHeaders]) {
for (const key in headers) {
const entry = headers[key];
processHeader(this, state, entry[0], entry[1], false);
@@ -486,9 +486,9 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
validateHeaderName(name);
validateHeaderValue(name, value);

let headers = this[outHeadersKey];
let headers = this[kOutHeaders];
if (headers === null)
this[outHeadersKey] = headers = Object.create(null);
this[kOutHeaders] = headers = Object.create(null);

headers[name.toLowerCase()] = [name, value];
};
@@ -497,7 +497,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
OutgoingMessage.prototype.getHeader = function getHeader(name) {
validateString(name, 'name');

const headers = this[outHeadersKey];
const headers = this[kOutHeaders];
if (headers === null)
return;

@@ -508,13 +508,13 @@ OutgoingMessage.prototype.getHeader = function getHeader(name) {

// Returns an array of the names of the current outgoing headers.
OutgoingMessage.prototype.getHeaderNames = function getHeaderNames() {
return this[outHeadersKey] !== null ? Object.keys(this[outHeadersKey]) : [];
return this[kOutHeaders] !== null ? Object.keys(this[kOutHeaders]) : [];
};


// Returns a shallow copy of the current outgoing headers.
OutgoingMessage.prototype.getHeaders = function getHeaders() {
const headers = this[outHeadersKey];
const headers = this[kOutHeaders];
const ret = Object.create(null);
if (headers) {
const keys = Object.keys(headers);
@@ -530,8 +530,8 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() {

OutgoingMessage.prototype.hasHeader = function hasHeader(name) {
validateString(name, 'name');
return this[outHeadersKey] !== null &&
!!this[outHeadersKey][name.toLowerCase()];
return this[kOutHeaders] !== null &&
!!this[kOutHeaders][name.toLowerCase()];
};


@@ -559,8 +559,8 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
break;
}

if (this[outHeadersKey] !== null) {
delete this[outHeadersKey][key];
if (this[kOutHeaders] !== null) {
delete this[kOutHeaders][key];
}
};

@@ -40,7 +40,7 @@ const {
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const {
outHeadersKey,
kOutHeaders,
ondrain,
nowDate,
emitStatistics
@@ -255,7 +255,7 @@ function writeHead(statusCode, reason, obj) {
this.statusCode = statusCode;

var headers;
if (this[outHeadersKey]) {
if (this[kOutHeaders]) {
// Slow-case: when progressive API and header fields are passed.
var k;
if (obj) {
@@ -269,7 +269,7 @@ function writeHead(statusCode, reason, obj) {
throw new ERR_HTTP_HEADERS_SENT('render');
}
// Only progressive api is used
headers = this[outHeadersKey];
headers = this[kOutHeaders];
} else {
// Only writeHead() called
headers = obj;
@@ -49,7 +49,7 @@ function emitStatistics(statistics) {
}

module.exports = {
outHeadersKey: Symbol('outHeadersKey'),
kOutHeaders: Symbol('kOutHeaders'),
ondrain,
nowDate,
utcDate,
@@ -5,7 +5,7 @@
const common = require('../common');
const assert = require('assert');

const { outHeadersKey } = require('internal/http');
const { kOutHeaders } = require('internal/http');

const http = require('http');
const modules = { http };
@@ -20,7 +20,7 @@ Object.keys(modules).forEach((module) => {
`${module}.request should not connect to ${module}://example.com%60x.example.com`
);
const req = modules[module].request(`${module}://example.com%60x.example.com`, doNotCall);
assert.deepStrictEqual(req[outHeadersKey].host, [
assert.deepStrictEqual(req[kOutHeaders].host, [
'Host',
'example.com`x.example.com',
]);
@@ -3,7 +3,7 @@
const common = require('../common');
const assert = require('assert');

const { outHeadersKey } = require('internal/http');
const { kOutHeaders } = require('internal/http');
const { OutgoingMessage } = require('http');

const warn = 'OutgoingMessage.prototype._headers is deprecated';
@@ -25,7 +25,7 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066');
};

assert.deepStrictEqual(
Object.entries(outgoingMessage[outHeadersKey]),
Object.entries(outgoingMessage[kOutHeaders]),
Object.entries({
host: ['host', 'risingstack.com'],
origin: ['Origin', 'localhost']
@@ -4,7 +4,7 @@
const common = require('../common');
const assert = require('assert');

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

@@ -23,22 +23,22 @@ const OutgoingMessage = http.OutgoingMessage;

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


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

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

0 comments on commit 6b9e372

Please sign in to comment.
You can’t perform that action at this time.