Preserve scheme, user, host, and port if the redirection doesn't have them

This commit is contained in:
Jay McCarthy 2012-08-09 15:09:22 -06:00
parent 2741356913
commit 23226b41da

View File

@ -234,9 +234,19 @@
=> =>
(λ (m) (λ (m)
(define m1 (list-ref m 1)) (define m1 (list-ref m 1))
(define url (with-handlers ((exn:fail? (λ (x) #f))) (define next-url
(string->url m1))) (with-handlers ((exn:fail? (λ (x) #f)))
(loop (or url new-url) chunked? (cons line headers)))] (define next-url (string->url m1))
(make-url
(or (url-scheme next-url) (url-scheme url))
(or (url-user next-url) (url-user url))
(or (url-host next-url) (url-host url))
(or (url-port next-url) (url-port url))
(url-path-absolute? next-url)
(url-path next-url)
(url-query next-url)
(url-fragment next-url))))
(loop (or next-url new-url) chunked? (cons line headers)))]
[else (loop new-url chunked? (cons line headers))]))) [else (loop new-url chunked? (cons line headers))])))
(define redirection-status-line? (define redirection-status-line?
(regexp-match #rx"^HTTP/[0-9]+[.][0-9]+ 3[0-9][0-9]" status)) (regexp-match #rx"^HTTP/[0-9]+[.][0-9]+ 3[0-9][0-9]" status))