Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ignoring explicit empty host header values #1258

Merged
merged 2 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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