当我在浏览器中使用 0.0.0.0 而不是 localhost 时,Chrome/server 会做什么?

What does Chrome/server do when I use 0.0.0.0 instead of localhost in browser?

我在 webpack 开发服务器中有一个单页应用程序 运行,用于在本地进行热重载。但是,它的后端应用程序不在我的本地,它是远程服务器中的主机,比如 http://remote-server.com.

当我在 chrome 地址字段中使用这样的地址时:0.0.0.0:3000/homepage,http 请求(api 调用远程后端服务器)比 5 倍(甚至更多)慢使用 localhost:3000/homepage

我真的很困惑为什么会这样?

实际上,更准确地说,问题是,当我要求 Chrome ping 0.0.0.0 时,browser/server 意味着什么,因为 0.0.0.0 只是被使用说 'bind to any possible address'

http请求是这样的

get /remote-server.com/api/v1/users
get /remote-server.com/api/v1/products
get /remote-server.com/api/v1/prices

当我使用 0.0.0.0localhost

时,我希望 http 请求花费相同的时间。

当我要求 Chrome ping 0.0.0.0 时,browser/server 是什么意思,因为 0.0.0.0 只是用来表示 'bind to any possible address'?

根据规范RFC57350.0.0.0只代表“源地址”,这意味着它是一个不可路由的地址,不能用于目的地。

但是,出于实际原因,许多客户端软件将 0.0.0.0 视为 localhost。此类软件列表包括:Chrome、Firefox、Safari、curl、telnet 等。因为许多 Web 服务器软件启动时都带有“listen on 0.0.0.0...”等消息,因此允许访问 0.0.0.0对初级开发者非常友好。

实际上,对于 Chrome,此行为被讨论为 issue,问题的状态一开始是“WontFix”,但后来更改为“已修复”,解决方案如下:

Allow explicit navigations to "0.0.0.0" to support systems where this performs a navigation to localhost (in defiance of specs... but seemingly common).

This still prevents navigation to any other IP with leading octet 0, and only allows 0.0.0.0 when it's actually entered in 4-component dotted-quad form.