Closed
Description
- Version: v7.6.0
- Platform: linux
- Subsystem: http
I'm not sure what's the idea behind defaulting to 127.0.0.1 in http.request
when hostname
is undefined
, but it's not a good one. Please throw an error when hostname
is anything but string, telling the user she's an idiot, rather than defaulting to some arbitrary IP address causing potentially dangerous and destructive side-effects (what if Trump's nukes are on the same port on 127.0.0.1?)
It's all cool that it's in the docs, but that doesn't mean it makes any sense or any good.
Common pitfall: undefined
slips into the variable used to fill hostname
, and all the user gets is this:
Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:1028:11)
at exports._exceptionWithHostPort (util.js:1051:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
Not even a hint of what is going on, or where.