vscode-httpyac icon indicating copy to clipboard operation
vscode-httpyac copied to clipboard

`localhost` seemingly seen as `127.0.0.1`

Open gerukin opened this issue 2 years ago • 2 comments

Hi Andreas... I think I either stumbled upon an issue... or I'm doing something wrong but can't figure out what.

When attempting to reach:

http://localhost:8787/something

The extension's output is:

RequestError: connect ECONNREFUSED 127.0.0.1:8787

Indeed 127.0.0.1:8787 is not a valid connection in my case, but localhost is. Not sure why this substitution happens. 🤷‍♂️

FYI I haven't seen any issues with the CLI 🎉.

gerukin avatar May 14 '22 08:05 gerukin

I have the problem when I want to call a service on the Windows host from the WSL. I think it is an overarching problem of WSL 2. I have not yet found the exact reason when localhost is replaced by 127.0.0.1. I suspect in the NodeJS core after resolution using the local hosts file. The stackoverflow post helped me. Or try https://docs.microsoft.com/en-us/windows/wsl/networking The solutions could also be helpful for using Docker, since presumably WSL2 is also used here.

AnWeber avatar May 14 '22 15:05 AnWeber

Hmmm, I'm not using WSL (I'm running VScode on a Mac), and I'm not sure why the CLI would be immune to this vs the vscode extension. Both are using NodeJS (albeit slightly different versions). Neither (I think) is using WSL in my case. 🤷‍♂️

gerukin avatar May 15 '22 09:05 gerukin

I also have this issue when using a proxy binded on localhost. Any request gives "RequestError: connect ECONNREFUSED 127.0.0.1:3128" because vscode proxy is set on http://localhost:3128.

Linux (Ubuntu), no WSL obviously, no docker.

boobin avatar Dec 07 '22 15:12 boobin

@boobin Can you possibly help me to create a setup how I can reproduce the error. I believe that it is not a bug of my code but more a general NodeJS or vscode problem. It could be some DNS.resolve issue like https://github.com/nodejs/node/issues/40702. Or I also got some problems with using vscode and the integrated VSCode Proxy override (change http.proxySupport from override to off)

AnWeber avatar Dec 08 '22 20:12 AnWeber

My issue using localhost as http proxy server seems to be resolved with the current versions of vscode and httpYac.

boobin avatar Mar 14 '23 13:03 boobin

I am closing the issue as the problem here is a DNS resolve. My extension only takes the standards of the NodeJS environment. It would be possible to implement special logic, but it should not be necessary.

AnWeber avatar Mar 14 '23 19:03 AnWeber