Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

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

I am having a single page application running in webpack dev server for hot reloading on my local. However, the backend application of it was not on my local, it was host in a remote server, say http://remote-server.com.

When I use such address in the chrome address field: 0.0.0.0:3000/homepage, the http request (api calls to remote backend server) was 5 times (even more) slower than using localhost:3000/homepage

I am really confused why would this happen?

Actually, more precisely, the question would be, what does it mean to a browser/server when I ask Chrome to ping 0.0.0.0, given the fact that 0.0.0.0 is simply used to say 'bind to any possible address'

The http requests are like

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

I was expecting the http requests takes the same amount of time.. when I use 0.0.0.0 and localhost

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

what does it mean to a browser/server when I ask Chrome to ping 0.0.0.0, given the fact that 0.0.0.0 is simply used to say 'bind to any possible address'?

By specification RFC5735, 0.0.0.0 only represents "source addresses", which means it is a non-routable address and cannot be used for destination.

However, for practical reason, many client software treat 0.0.0.0 as localhost. Such software list includes: Chrome, Firefox, Safari, curl, telnet etc. Because, as many web server software launch with messages like "listen on 0.0.0.0...", allow visiting to 0.0.0.0 is very user-friendly for junior developers.

Actually, for Chrome, this behavior was discussed as an issue, the issue's status was "WontFix" at the beginning, but later changed to "Fixed" with following solution:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...