Who is wrong in http: // 0: port?

Plack typically uses http://0:port . For example. the following

 plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' 

prints

 HTTP::Server::PSGI: Accepting connections at http://0:5000/ 

However, LWP::UserAgent (or some deeper modules) did not accept it, for example:

 perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://0:5000/valid/path");print $res->status_line' 

prints:

 500 No Host option provided 

but

 perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://localhost:5000/valid/path");print $res->status_line' 

prints

 200 OK 

Question: who is wrong?

  • Is http://0:port valid, e.g. LWP is "wrong."
  • or is it invalid and does the PSGI use it as a β€œrandom valid” label?
+7
perl lwp psgi
source share
2 answers

The output of the Plack package is the output of the server . Typically, the bind s server connects to a specific port and address to serve content there. The designation http://0:port means in this case: listen on port port on all addresses of this unit. This is convenient if you do not know or do not want to specify all the addresses of the machine on which access to the server should be.

The output of LWP :: UserAgent is output at the output of the client . To open a connection to the server, you must explicitly specify the address and port for the connection. 0 not a valid IP address, so the connection fails if you connect to http://0:port .

+6
source

Safari 11, curl and wget allow http://0:5000 to http://0.0.0.0:5000 and connect to the local host.

I just checked it by seeing the url and finding the answer to the question, unhappy.

0
source

All Articles