diff options
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r-- | lib/_http_outgoing.js | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 9d308525c6..ba5d226e7b 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -34,16 +34,19 @@ const { symbols: { async_id_symbol } } = require('internal/async_hooks'); const { - ERR_HTTP_HEADERS_SENT, - ERR_HTTP_INVALID_HEADER_VALUE, - ERR_HTTP_TRAILER_INVALID, - ERR_INVALID_HTTP_TOKEN, - ERR_INVALID_ARG_TYPE, - ERR_INVALID_CHAR, - ERR_METHOD_NOT_IMPLEMENTED, - ERR_STREAM_CANNOT_PIPE, - ERR_STREAM_WRITE_AFTER_END -} = require('internal/errors').codes; + codes: { + ERR_HTTP_HEADERS_SENT, + ERR_HTTP_INVALID_HEADER_VALUE, + ERR_HTTP_TRAILER_INVALID, + ERR_INVALID_HTTP_TOKEN, + ERR_INVALID_ARG_TYPE, + ERR_INVALID_CHAR, + ERR_METHOD_NOT_IMPLEMENTED, + ERR_STREAM_CANNOT_PIPE, + ERR_STREAM_WRITE_AFTER_END + }, + hideStackFrames +} = require('internal/errors'); const { validateString } = require('internal/validators'); const { CRLF, debug } = common; @@ -443,39 +446,21 @@ function matchHeader(self, state, field, value) { } } -function validateHeaderName(name) { +const validateHeaderName = hideStackFrames((name) => { if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) { - // Reducing the limit improves the performance significantly. We do not - // lose the stack frames due to the `captureStackTrace()` function that is - // called later. - const tmpLimit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; - const err = new ERR_INVALID_HTTP_TOKEN('Header name', name); - Error.stackTraceLimit = tmpLimit; - Error.captureStackTrace(err, validateHeaderName); - throw err; + throw new ERR_INVALID_HTTP_TOKEN('Header name', name); } -} +}); -function validateHeaderValue(name, value) { - let err; - // Reducing the limit improves the performance significantly. We do not loose - // the stack frames due to the `captureStackTrace()` function that is called - // later. - const tmpLimit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; +const validateHeaderValue = hideStackFrames((name, value) => { if (value === undefined) { - err = new ERR_HTTP_INVALID_HEADER_VALUE(value, name); - } else if (checkInvalidHeaderChar(value)) { - debug('Header "%s" contains invalid characters', name); - err = new ERR_INVALID_CHAR('header content', name); + throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name); } - Error.stackTraceLimit = tmpLimit; - if (err !== undefined) { - Error.captureStackTrace(err, validateHeaderValue); - throw err; + if (checkInvalidHeaderChar(value)) { + debug('Header "%s" contains invalid characters', name); + throw new ERR_INVALID_CHAR('header content', name); } -} +}); OutgoingMessage.prototype.setHeader = function setHeader(name, value) { if (this._header) { |