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

http: symbol naming convention #29091

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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() {
Expand Down
34 changes: 17 additions & 17 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +104,7 @@ function OutgoingMessage() {
this.socket = null;
this.connection = null;
this._header = null;
this[outHeadersKey] = null;
this[kOutHeaders] = null;

this._onPendingData = noopPendingOutput;
}
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
};
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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()];
};


Expand Down Expand Up @@ -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];
}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const {
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const {
outHeadersKey,
kOutHeaders,
ondrain,
nowDate,
emitStatistics
Expand Down Expand Up @@ -252,7 +252,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) {
Expand All @@ -266,7 +266,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;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function emitStatistics(statistics) {
}

module.exports = {
outHeadersKey: Symbol('outHeadersKey'),
kOutHeaders: Symbol('kOutHeaders'),
ondrain,
nowDate,
utcDate,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-correct-hostname.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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',
]);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-outgoing-internal-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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']
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-http-outgoing-renderHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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']
};
Expand Down