Skip to content

Commit c8ad127

Browse files
mscdexevanlucas
authored andcommitted
http: extract validation functions
PR-URL: #6533 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent aed5e27 commit c8ad127

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/_http_outgoing.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const util = require('util');
77
const internalUtil = require('internal/util');
88
const Buffer = require('buffer').Buffer;
99
const common = require('_http_common');
10+
const checkIsHttpToken = common._checkIsHttpToken;
11+
const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
1012

1113
const CRLF = common.CRLF;
1214
const trfrEncChunkExpression = common.chunkExpression;
@@ -312,11 +314,11 @@ function _storeHeader(firstLine, headers) {
312314
}
313315

314316
function storeHeader(self, state, field, value) {
315-
if (!common._checkIsHttpToken(field)) {
317+
if (!checkIsHttpToken(field)) {
316318
throw new TypeError(
317319
'Header name must be a valid HTTP Token ["' + field + '"]');
318320
}
319-
if (common._checkInvalidHeaderChar(value) === true) {
321+
if (checkInvalidHeaderChar(value)) {
320322
debug('Header "%s" contains invalid characters', field);
321323
throw new TypeError('The header content contains invalid characters');
322324
}
@@ -350,14 +352,14 @@ function storeHeader(self, state, field, value) {
350352

351353

352354
OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
353-
if (!common._checkIsHttpToken(name))
355+
if (!checkIsHttpToken(name))
354356
throw new TypeError(
355357
'Header name must be a valid HTTP Token ["' + name + '"]');
356358
if (value === undefined)
357359
throw new Error('"value" required in setHeader("' + name + '", value)');
358360
if (this._header)
359361
throw new Error('Can\'t set headers after they are sent.');
360-
if (common._checkInvalidHeaderChar(value) === true) {
362+
if (checkInvalidHeaderChar(value)) {
361363
debug('Header "%s" contains invalid characters', name);
362364
throw new TypeError('The header content contains invalid characters');
363365
}
@@ -530,11 +532,11 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
530532
field = key;
531533
value = headers[key];
532534
}
533-
if (!common._checkIsHttpToken(field)) {
535+
if (!checkIsHttpToken(field)) {
534536
throw new TypeError(
535537
'Trailer name must be a valid HTTP Token ["' + field + '"]');
536538
}
537-
if (common._checkInvalidHeaderChar(value) === true) {
539+
if (checkInvalidHeaderChar(value)) {
538540
debug('Trailer "%s" contains invalid characters', field);
539541
throw new TypeError('The trailer content contains invalid characters');
540542
}

0 commit comments

Comments
 (0)