http-client: Correctly handle redirects when #:keep-alive? #t.
Previously PORT would be closed unconditionally, which broke redirects when #:keep-alive? #t is given. * guix/http-client.scm (http-fetch): Make 'port' a parameter of 'loop'. Upon 3xx responses, do not close PORT is KEEP-ALIVE? is true, but consume RESP's body. Add second argument to 'loop'.master
parent
55e8e283ae
commit
8786c2e8d7
|
@ -100,14 +100,15 @@ TIMEOUT is #f, connection establishment never times out.
|
||||||
Write information about redirects to LOG-PORT.
|
Write information about redirects to LOG-PORT.
|
||||||
|
|
||||||
Raise an '&http-get-error' condition if downloading fails."
|
Raise an '&http-get-error' condition if downloading fails."
|
||||||
(let loop ((uri (if (string? uri)
|
(define uri*
|
||||||
(string->uri uri)
|
(if (string? uri) (string->uri uri) uri))
|
||||||
uri)))
|
|
||||||
(let ((port (or port (open-connection uri
|
(let loop ((uri uri*)
|
||||||
|
(port (or port (open-connection uri*
|
||||||
#:verify-certificate?
|
#:verify-certificate?
|
||||||
verify-certificate?
|
verify-certificate?
|
||||||
#:timeout timeout)))
|
#:timeout timeout))))
|
||||||
(headers (match (uri-userinfo uri)
|
(let ((headers (match (uri-userinfo uri)
|
||||||
((? string? str)
|
((? string? str)
|
||||||
(cons (cons 'Authorization
|
(cons (cons 'Authorization
|
||||||
(string-append "Basic "
|
(string-append "Basic "
|
||||||
|
@ -131,11 +132,23 @@ Raise an '&http-get-error' condition if downloading fails."
|
||||||
303 ; see other
|
303 ; see other
|
||||||
307 ; temporary redirection
|
307 ; temporary redirection
|
||||||
308) ; permanent redirection
|
308) ; permanent redirection
|
||||||
(let ((uri (resolve-uri-reference (response-location resp) uri)))
|
(let ((host (uri-host uri))
|
||||||
(close-port port)
|
(uri (resolve-uri-reference (response-location resp) uri)))
|
||||||
|
(if keep-alive?
|
||||||
|
(dump-port data (%make-void-port "w0")
|
||||||
|
(response-content-length resp))
|
||||||
|
(close-port port))
|
||||||
(format log-port (G_ "following redirection to `~a'...~%")
|
(format log-port (G_ "following redirection to `~a'...~%")
|
||||||
(uri->string uri))
|
(uri->string uri))
|
||||||
(loop uri)))
|
(loop uri
|
||||||
|
(or (and keep-alive?
|
||||||
|
(or (not (uri-host uri))
|
||||||
|
(string=? host (uri-host uri)))
|
||||||
|
port)
|
||||||
|
(open-connection uri*
|
||||||
|
#:verify-certificate?
|
||||||
|
verify-certificate?
|
||||||
|
#:timeout timeout)))))
|
||||||
(else
|
(else
|
||||||
(raise (condition (&http-get-error
|
(raise (condition (&http-get-error
|
||||||
(uri uri)
|
(uri uri)
|
||||||
|
|
Reference in New Issue