mighty-gerbils / gerbil

Gerbil Scheme
https://cons.io
GNU Lesser General Public License v2.1
1.15k stars 109 forks source link

strange :std/net/request failures #23

Closed wfatp closed 7 years ago

wfatp commented 7 years ago

Unfortunately requesting pages seems to be hit and miss:

[georgiy@PANTHER ~]$ gxi Gerbil v0.12-DEV on Gambit v4.8.8

(import :std/net/request)
(http-get "http://hitchtheworld.com")

<request #7>

(http-get "http://debian.org")
*** ERROR IN (console)@3.1 -- URL redirection loop "http://www.debian.org/" 1>

For some reason it's not able to get the Debian home page among others the way any of my browsers can and the way I can get with Python's Requests library.

vyzo commented 7 years ago

Maybe there is some cookie involved here. Can you try with (http-get url redirect: #f) and check the request status and cookies? I can add support for tracking cookies upon redirect.

wfatp commented 7 years ago

[georgiy@PANTHER ~]$ gxi Gerbil v0.12-DEV on Gambit v4.8.8

(import :std/net/request) (def response (http-get "http://debian.org" redirect: #f)) (request-cookies response) () (request-status response) 301

wfatp commented 7 years ago

Also why is the function even called request-status? Requests don't have status codes, only responses do.

vyzo commented 7 years ago

The function is called request-status because the object is called request.

So the issue seem to be in the headers containing a wrong host I think. This works:

> (http-get "http://debian.org" redirect: #f)
#<request #7>
> (request-headers #7)
(("Date" . "Fri, 08 Sep 2017 22:01:25 GMT")
 ("Server" . "Apache")
 ("X-Content-Type-Options" . "nosniff")
 ("X-Frame-Options" . "sameorigin")
 ("Referrer-Policy" . "no-referrer")
 ("X-Xss-Protection" . "1")
 ("Location" . "http://www.debian.org/")
 ("Content-Length" . "290")
 ("Connection" . "close")
 ("Content-Type" . "text/html; charset=iso-8859-1"))
> (http-get "http://www.debian.org" redirect: #f)
#<request #8>
> (request-headers #8)
(("Date" . "Fri, 08 Sep 2017 22:01:44 GMT")
 ("Server" . "Apache")
 ("Content-Location" . "index.en.html")
 ("Vary" . "negotiate,accept-language,Accept-Encoding")
 ("Tcn" . "choice")
 ("X-Content-Type-Options" . "nosniff")
 ("X-Frame-Options" . "sameorigin")
 ("Referrer-Policy" . "no-referrer")
 ("X-Xss-Protection" . "1")
 ("Last-Modified" . "Wed, 06 Sep 2017 11:34:34 GMT")
 ("Etag" . "\"3be8-55883ba5b59fc-gzip\"")
 ("Accept-Ranges" . "bytes")
 ("Content-Encoding" . "gzip")
 ("Cache-Control" . "max-age=86400")
 ("Expires" . "Sat, 09 Sep 2017 22:01:44 GMT")
 ("X-Clacks-Overhead" . "GNU Terry Pratchett")
 ("Content-Length" . "4735")
 ("Connection" . "close")
 ("Content-Type" . "text/html")
 ("Content-Language" . "en"))
> (request-status #8)
200
> (request-status #7)
301
vyzo commented 7 years ago

Fixed by #25; thanks for reporting the bug!

wfatp commented 7 years ago

Thank you for fixing. :-)