summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-04-18 13:33:51 -0700
committerJames M Snell <jasnell@gmail.com>2017-04-24 10:49:12 -0700
commit85a4e257759d0da3dbebb501069a8a1f7130a392 (patch)
treee86c1902e1fd9dee8a41f47c61639bc9e4751fdc /lib
parentb968d584af9e569aeb1fdbc4399ff9752378b41f (diff)
downloadandroid-node-v8-85a4e257759d0da3dbebb501069a8a1f7130a392.tar.gz
android-node-v8-85a4e257759d0da3dbebb501069a8a1f7130a392.tar.bz2
android-node-v8-85a4e257759d0da3dbebb501069a8a1f7130a392.zip
http: add type checking for hostname
Add type checking for options.hostname / options.host Maintains the use of `undefined` and `null` for default `localhost`, but other falsy values (like `false`, `0` and `NaN`) are rejected. PR-URL: https://github.com/nodejs/node/pull/12494 Ref: https://github.com/nodejs/node/issues/12488 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_client.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 2205e89d2a..42387d0930 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -65,6 +65,14 @@ function isInvalidPath(s) {
return false;
}
+function validateHost(host, name) {
+ if (host != null && typeof host !== 'string') {
+ throw new TypeError(
+ `"options.${name}" must either be a string, undefined or null`);
+ }
+ return host;
+}
+
function ClientRequest(options, cb) {
OutgoingMessage.call(this);
@@ -123,7 +131,8 @@ function ClientRequest(options, cb) {
this.agent && this.agent.defaultPort;
var port = options.port = options.port || defaultPort || 80;
- var host = options.host = options.hostname || options.host || 'localhost';
+ var host = options.host = validateHost(options.hostname, 'hostname') ||
+ validateHost(options.host, 'host') || 'localhost';
var setHost = (options.setHost === undefined);