Skip to content

Commit

Permalink
Manually add Host header when passed as Array
Browse files Browse the repository at this point in the history
Notably, when `request#options.headers` is an Array, the `Host`
header won't be automatically set. In prior versions of node
this wasn't of much consequence, but as of [1] its enforced.

[1] nodejs/node#45597
  • Loading branch information
griffinmyers committed Apr 18, 2023
1 parent 9e4a041 commit 2825d9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export const req = ({
}

if (Array.isArray(headers)) {
headers = [...Object.entries(bodyHeaders).flat(), ...headers];
headers = [
...Object.entries(bodyHeaders).flat(),
'Host',
`localhost:${port}`,
...headers,
];
} else {
headers = { ...bodyHeaders, ...headers };
}
Expand Down

0 comments on commit 2825d9e

Please sign in to comment.