summaryrefslogtreecommitdiff
path: root/lib/_http_outgoing.js
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2018-08-02 18:51:02 -0400
committerJon Moss <me@jonathanmoss.me>2018-08-07 10:51:27 -0400
commite570ae79f5b1d74fed52d2aed7f014caaa0836dd (patch)
tree004749b9ff1a59964ba7186c105956614671e48a /lib/_http_outgoing.js
parent080316b32a0e6320e012214c32725099a0248de6 (diff)
downloadandroid-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.tar.gz
android-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.tar.bz2
android-node-v8-e570ae79f5b1d74fed52d2aed7f014caaa0836dd.zip
lib: extract validateString validator
Pulls out a common argument validator to `internal/validators` PR-URL: https://github.com/nodejs/node/pull/22101 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r--lib/_http_outgoing.js14
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index d150a9d93c..7fe4e2133b 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -45,6 +45,7 @@ const {
ERR_STREAM_CANNOT_PIPE,
ERR_STREAM_WRITE_AFTER_END
} = require('internal/errors').codes;
+const { validateString } = require('internal/validators');
const { CRLF, debug } = common;
@@ -480,9 +481,7 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
OutgoingMessage.prototype.getHeader = function getHeader(name) {
- if (typeof name !== 'string') {
- throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
- }
+ validateString(name, 'name');
const headers = this[outHeadersKey];
if (headers === null)
@@ -516,19 +515,14 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() {
OutgoingMessage.prototype.hasHeader = function hasHeader(name) {
- if (typeof name !== 'string') {
- throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
- }
-
+ validateString(name, 'name');
return this[outHeadersKey] !== null &&
!!this[outHeadersKey][name.toLowerCase()];
};
OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
- if (typeof name !== 'string') {
- throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
- }
+ validateString(name, 'name');
if (this._header) {
throw new ERR_HTTP_HEADERS_SENT('remove');