7

The Plack suite commonly uses the http://0:port. E.g. the following

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

prints

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

However, the LWP::UserAgent (or some deeper called modules) didn't accepts it, e.g. the:

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 the

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

prints

200 OK

The question is: who is wrong?

  • Is the http://0:port valid, e.g. the LWP is "wrong"
  • or it isn't valid and the PSGI uses it as only "randomly valid" shortcut?
kobame
  • 5,766
  • 3
  • 31
  • 62
  • 1
    Localhost is not address `0`, it's (typically) `127.0.0.1`. Try pinging `localhost` to see the actual address. – Some programmer dude Jul 06 '15 at 09:55
  • 1
    This is relevant: http://lists.scsys.co.uk/pipermail/catalyst/2012-April/028434.html – simbabque Jul 06 '15 at 09:58
  • 1
    @JoachimPileborg ok, edited the question title. :) The question's merit is remain: the url `http://0:5000` is valid or no? Could/should be used or no? – kobame Jul 06 '15 at 10:08
  • Address `0` is the wildcard address used by servers when they want to listen to connections from all interfaces. It makes no sense trying to connect to it. – Some programmer dude Jul 06 '15 at 10:21

2 Answers2

6

The output of the Plack suite is the output of a server. A server typically binds a socket to a certain port and address in order to serve content there. The notation http://0:port means in this case: listen on port port on all addresses of this machine. This is handy if you don't know or don't want to specify all addresses of the machine where the server should be reachable.

The output of the LWP::UserAgent ist the output of a client. In order to open a connection to a server, you must explicitly specify the address and the port to connect to. 0 is no valid IP address, therefore the connection fails when you connect to http://0:port.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • The `http://0:port` is an *URL*. So, the `http://0:5000` isn't valid URL and it is "only" _handy_. Right? – kobame Jul 06 '15 at 10:24
  • it's no valid URL. It's just the result of a `printf` somewhere in the code of Plack. A server doesn't bind to a URL but to the combination of IP address and port. – eckes Jul 06 '15 at 10:25
  • 1
    okay, understand the bind - but the PSGI prints an *URL*, e.g. `http://0:5000` . ok - now know - it prints an invalid URL, but it is handy in many situations - many browsers just translates it to `127.0.0.1`. Thanx. :) – kobame Jul 06 '15 at 10:28
  • 4
    While the answer is correct it should contain: the printed URL isn't valid. (and imho, using the `http://*:5000` would be more clear - however it isn't as handy as `0:5000`. :) +1 anyway :) – clt60 Jul 06 '15 at 11:26
0

Safari 11, curl and wget resolve http://0:5000 to http://0.0.0.0:5000 and connect to the localhost.

I just tested it, after seeing the URL and finding the answer to the question dissatisfying.

Richard Metzler
  • 545
  • 7
  • 17