Skip to content

Commit

Permalink
Fix for ignoring explicit empty host header values (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoodman committed Mar 2, 2022
1 parent 901f9d6 commit 35cc2f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Expand Up @@ -1481,7 +1481,7 @@ function write (client, request) {

let header = `${method} ${path} HTTP/1.1\r\n`

if (host) {
if (typeof host === 'string') {
header += `host: ${host}\r\n`
} else {
header += client[kHostHeader]
Expand Down
28 changes: 28 additions & 0 deletions test/client-request.js
Expand Up @@ -281,6 +281,34 @@ test('request text', (t) => {
})
})

test('empty host header', (t) => {
t.plan(3)

const server = createServer((req, res) => {
res.end(req.headers.host)
})
t.teardown(server.close.bind(server))

server.listen(0, async () => {
const serverAddress = `localhost:${server.address().port}`;
const client = new Client(`http://${serverAddress}`)
t.teardown(client.destroy.bind(client))

const getWithHost = async (host, wanted) => {
const { body } = await client.request({
path: '/',
method: 'GET',
headers: { host }
})
t.strictSame(await body.text(), wanted)
}

await getWithHost('test', 'test')
await getWithHost(undefined, serverAddress)
await getWithHost('', '')
})
})

test('request long multibyte text', (t) => {
t.plan(1)

Expand Down

0 comments on commit 35cc2f3

Please sign in to comment.