http: extract validation functions
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
b6ea857c7d
commit
e8b809a7a0
@ -7,6 +7,8 @@ const util = require('util');
|
|||||||
const internalUtil = require('internal/util');
|
const internalUtil = require('internal/util');
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
const common = require('_http_common');
|
const common = require('_http_common');
|
||||||
|
const checkIsHttpToken = common._checkIsHttpToken;
|
||||||
|
const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
|
||||||
|
|
||||||
const CRLF = common.CRLF;
|
const CRLF = common.CRLF;
|
||||||
const trfrEncChunkExpression = common.chunkExpression;
|
const trfrEncChunkExpression = common.chunkExpression;
|
||||||
@ -312,11 +314,11 @@ function _storeHeader(firstLine, headers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function storeHeader(self, state, field, value) {
|
function storeHeader(self, state, field, value) {
|
||||||
if (!common._checkIsHttpToken(field)) {
|
if (!checkIsHttpToken(field)) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'Header name must be a valid HTTP Token ["' + field + '"]');
|
'Header name must be a valid HTTP Token ["' + field + '"]');
|
||||||
}
|
}
|
||||||
if (common._checkInvalidHeaderChar(value) === true) {
|
if (checkInvalidHeaderChar(value)) {
|
||||||
debug('Header "%s" contains invalid characters', field);
|
debug('Header "%s" contains invalid characters', field);
|
||||||
throw new TypeError('The header content contains invalid characters');
|
throw new TypeError('The header content contains invalid characters');
|
||||||
}
|
}
|
||||||
@ -350,14 +352,14 @@ function storeHeader(self, state, field, value) {
|
|||||||
|
|
||||||
|
|
||||||
OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
|
OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
|
||||||
if (!common._checkIsHttpToken(name))
|
if (!checkIsHttpToken(name))
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'Header name must be a valid HTTP Token ["' + name + '"]');
|
'Header name must be a valid HTTP Token ["' + name + '"]');
|
||||||
if (value === undefined)
|
if (value === undefined)
|
||||||
throw new Error('"value" required in setHeader("' + name + '", value)');
|
throw new Error('"value" required in setHeader("' + name + '", value)');
|
||||||
if (this._header)
|
if (this._header)
|
||||||
throw new Error('Can\'t set headers after they are sent.');
|
throw new Error('Can\'t set headers after they are sent.');
|
||||||
if (common._checkInvalidHeaderChar(value) === true) {
|
if (checkInvalidHeaderChar(value)) {
|
||||||
debug('Header "%s" contains invalid characters', name);
|
debug('Header "%s" contains invalid characters', name);
|
||||||
throw new TypeError('The header content contains invalid characters');
|
throw new TypeError('The header content contains invalid characters');
|
||||||
}
|
}
|
||||||
@ -530,11 +532,11 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
|
|||||||
field = key;
|
field = key;
|
||||||
value = headers[key];
|
value = headers[key];
|
||||||
}
|
}
|
||||||
if (!common._checkIsHttpToken(field)) {
|
if (!checkIsHttpToken(field)) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'Trailer name must be a valid HTTP Token ["' + field + '"]');
|
'Trailer name must be a valid HTTP Token ["' + field + '"]');
|
||||||
}
|
}
|
||||||
if (common._checkInvalidHeaderChar(value) === true) {
|
if (checkInvalidHeaderChar(value)) {
|
||||||
debug('Trailer "%s" contains invalid characters', field);
|
debug('Trailer "%s" contains invalid characters', field);
|
||||||
throw new TypeError('The trailer content contains invalid characters');
|
throw new TypeError('The trailer content contains invalid characters');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user