| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0c6cf8 commit 2daf883
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,11 @@ const net = require('net'); | |||
| 27 | 27 | const EventEmitter = require('events'); | |
| 28 | 28 | const debug = require('internal/util/debuglog').debuglog('http'); | |
| 29 | 29 | const { async_id_symbol } = require('internal/async_hooks').symbols; | |
| 30 | - | ||
| 30 | + const { | ||
| 31 | + codes: { | ||
| 32 | + ERR_INVALID_ARG_TYPE, | ||
| 33 | + }, | ||
| 34 | + } = require('internal/errors'); | ||
| 31 | 35 | // New Agent code. | |
| 32 | 36 | ||
| 33 | 37 | // The largest departure from the previous implementation is that | |
@@ -240,6 +244,11 @@ function calculateServerName(options, req) { | |||
| 240 | 244 | let servername = options.host; | |
| 241 | 245 | const hostHeader = req.getHeader('host'); | |
| 242 | 246 | if (hostHeader) { | |
| 247 | + if (typeof hostHeader !== 'string') { | ||
| 248 | + throw new ERR_INVALID_ARG_TYPE('options.headers.host', | ||
| 249 | + 'String', hostHeader); | ||
| 250 | + } | ||
| 251 | + | ||
| 243 | 252 | // abc => abc | |
| 244 | 253 | // abc:123 => abc | |
| 245 | 254 | // [::1] => ::1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const http = require('http'); | ||
| 7 | + | ||
| 8 | + { | ||
| 9 | + | ||
| 10 | + const options = { | ||
| 11 | + port: '80', | ||
| 12 | + path: '/', | ||
| 13 | + headers: { | ||
| 14 | + host: [] | ||
| 15 | + } | ||
| 16 | + }; | ||
| 17 | + | ||
| 18 | + assert.throws(() => { | ||
| 19 | + http.request(options); | ||
| 20 | + }, { | ||
| 21 | + code: /ERR_INVALID_ARG_TYPE/ | ||
| 22 | + }, 'http request should throw when passing array as header host'); | ||
| 23 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments