edicl / drakma

HTTP client written in Common Lisp
http://edicl.github.io/drakma/
249 stars 58 forks source link

localhost request fails with PHP built-in webserver #98

Closed iharsuvorau closed 5 years ago

iharsuvorau commented 5 years ago

I'm not sure it's the issue with drakma, because dexador, for example, fails in the same way. So, please, maybe you can point to where should I look to solve the issue. The long version is on the stackoverflow still open question.

Seems like the problem is related to the particular PHP built-it webserver for development, because the issue is reproducible only with:

But the PHP webserver serves fine for curl, a Go client, a web browser.

PHP version:

PHP 7.3.1 (cli) (built: Jan 10 2019 13:16:34) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies

-- installed with brew install php.

Steps to reproduce

The server:

php -S localhost:7070

Then try with clients:

curl "http://localhost:7070"

-- works fine (status code 404 is expected and received).

Lisp:

(drakma:http-request "http://localhost:7070")

-- fails (status code 404 is expected but connection refused is returned).

stassats commented 5 years ago

Is localhost correctly resolving? There is no ipv4-ipv6 discrepancies?

iharsuvorau commented 5 years ago

@stassats

Is localhost correctly resolving?

I request the localhost with curl successfully, seems like it resolves correctly, doesn't it? dig localhost → 127.0.0.1

There is no ipv4-ipv6 discrepancies?

How do I check this? Still, it works fine for web browsers, curl and Go-programs at least.

stassats commented 5 years ago

Does (drakma:http-request "http://127.0.0.1:7070") work?

iharsuvorau commented 5 years ago

@stassats

Does (drakma:http-request "http://127.0.0.1:7070") work?

Nope. The same USOCKET:CONNECTION-REFUSED-ERROR error.

stassats commented 5 years ago

And curl http://127.0.0.1:7070 ?

iharsuvorau commented 5 years ago

@stassats

And curl http://127.0.0.1:7070 ?

Well, curl also fails with Connection refused using 127.0.0.1:7070, but works with localhost:7070. Why is that?

stassats commented 5 years ago

netstat -n | grep 7070

iharsuvorau commented 5 years ago

@stassats

netstat -n | grep 7070

Got nothing.

stassats commented 5 years ago

Rather do lsof -n -i:7070

iharsuvorau commented 5 years ago

@stassats

lsof -n -i:7070

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
php     96090 ihar    7u  IPv6 0x7ad446e2d88a5083      0t0  TCP [::1]:arcp (LISTEN)
stassats commented 5 years ago

So, it's listening on an ipv6 address indeed. I guess start it with php -S 127.0.0.1:7070

iharsuvorau commented 5 years ago

@stassats

So, it's listening on an ipv6 address indeed. I guess start it with php -S 127.0.0.1:7070

You're correct. That works. Thanks a lot for your time explaining that to me.