eugef / node-mocks-http

Mock 'http' objects for testing Express,js, Next.js and Koa routing functions
Other
755 stars 134 forks source link

req.hostname doesn't reflect real hostname #230

Closed jereaameli closed 3 years ago

jereaameli commented 3 years ago

Bug

PR #224 introduced a feature where req.hostname get's calculated from the Host header, but it wrongly truncates it to the 2 upper domains.

For example:

Solution

req.hostname should reflect exactly the same value as the Host header, without the port information if it was included, and all subdomains must be included.

Reference

For reference, here we can see how Express calculates the hostname value.

eugef commented 3 years ago

Hi @jereaameli, thank you for reporting the issue, the fix will be released in the next version