Skip to content

Commit 474a66a

Browse files
committed
http: handle arrrays in host prop
submodule: http handle passing array in host prop of agent headers
1 parent f2e35ff commit 474a66a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/_http_agent.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ const net = require('net');
2727
const EventEmitter = require('events');
2828
const debug = require('internal/util/debuglog').debuglog('http');
2929
const { async_id_symbol } = require('internal/async_hooks').symbols;
30-
30+
const {
31+
codes: {
32+
ERR_INVALID_ARG_TYPE,
33+
},
34+
} = require('internal/errors');
3135
// New Agent code.
3236

3337
// The largest departure from the previous implementation is that
@@ -240,6 +244,11 @@ function calculateServerName(options, req) {
240244
let servername = options.host;
241245
const hostHeader = req.getHeader('host');
242246
if (hostHeader) {
247+
if (typeof hostHeader !== 'string') {
248+
throw new ERR_INVALID_ARG_TYPE('options.headers.host',
249+
'String', hostHeader);
250+
}
251+
243252
// abc => abc
244253
// abc:123 => abc
245254
// [::1] => ::1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)