libwww-perl / HTTP-Daemon

A simple http server class
http://metacpan.org/release/HTTP-Daemon/
Other
6 stars 16 forks source link

prefer ip address for host in $d->url #40

Closed skaji closed 4 years ago

skaji commented 4 years ago

This PR will fix #38, that is "Sometimes cannot be accessed via $d->url".

When we are not able to access servers via $d->url

Let's say we create an HTTP::Daemon server by

my $d = HTTP::Daemon->new()

Then, $d->sockaddr is INADDR_ANY (0.0.0.0) or IN6ADDR_ANY (::1), so $d->url returns http://hostname:XXX/, where hostname is the hostname of the local machine returned by Sys::Hostname::hostname, and XXX is some port number.

Then, there are 2 cases that we are not able to access the server via $d->url:

How to fix it

Backward compatibility

Although this PR will fix #38, we should note that this PR may break some use cases.

As I mentioned above, currently, when we create HTTP::Daemon by my $d = HTTP::Daemon->new, $d->url becomes http://hostname:XXX. But after this PR, $d->url will become http://127.0.0.1:XXX or http://[::1]:XXX.

Apparently, the ip addresses 127.0.0.1 and ::1 are reasonable only in the local machine. On the other hand, the hostname may be reasonable not only in local machine, but also in remote machines.

So this PR may cause an issue "we are not able to access servers from remote machines via $d->url".

jkeenan commented 4 years ago

So far so good. I applied your patch to existing HTTP-Daemon-6.07 and called the result 6.07_001. I added one more debugging line to your first test program so as to print the perlversion. Results on 3 BSDs:

FreeBSD

$ uname -mrs
FreeBSD 11.2-STABLE amd64

$ perl -I/usr/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib skaji-http-daemon-gh38-test.pl
Perl version:           v5.28.2
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.18
HTTP GET http://[::1]:64633/
200 OK

$ bleadperl -I/usr/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib skaji-http-daemon-gh38-test.pl
Perl version:           v5.31.12
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.22
HTTP GET http://[::1]:10182/
200 OK

OpenBSD

$ uname -mrs
OpenBSD 6.6 amd64

$ perl -I/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib skaji-http-daemon->
Perl version:           v5.28.2
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.13
HTTP GET http://127.0.0.1:22871/
200 OK

$ bleadperl -I/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib skaji-http-da>
Perl version:           v5.31.12
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.22
HTTP GET http://127.0.0.1:6970/
200 OK

NetBSD

$ uname -mrs
NetBSD 8.0 amd64

$ perl -I/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib   skaji-http-daemon-gh38-test.pl
Perl version:           v5.30.2
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.18
HTTP GET http://[::1]:65393/
200 OK

$ bleadperl -I/home/jkeenan/learn/perl/HTTP-Daemon-6.07-patched/lib   skaji-http-daemon-gh38-test.pl
Perl version:           v5.32.0
HTTP::Daemon version:   6.07_001
HTTP::Response version: 6.24
HTTP GET http://[::1]:65391/
200 OK

I have not yet had an opportunity to run the Test-Smoke test suite with this patch but will try to do so in the coming days. Please let me know what other testing procedures you might need.

Thank you very much. Jim Keenan

jkeenan commented 4 years ago

So far so good. I applied your patch to existing HTTP-Daemon-6.07 and called the result 6.07_001. I added one more debugging line to your first test program so as to print the perlversion. Results on 3 BSDs:

[snip]

I have not yet had an opportunity to run the Test-Smoke test suite with this patch but will try to do so in the coming days. Please let me know what other testing procedures you might need.

I have now run the Test-Smoke test suite with your patched HTTP::Daemon. Please see: https://rt.cpan.org/Ticket/Display.html?id=132642#txn-1898592

These results suggest that while LWP::UserAgent and HTTP::Tiny "play well" with the patched version of HTTP::Daemon, HTTP::Lite has problems.

Thank you very much. Jim Keenan

oalders commented 4 years ago

Thanks everyone!