From 3a69c972980251af21c731f771d0e61625593bb9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 23 Apr 2008 01:42:30 -0500 Subject: [PATCH] https:// is absolute --- extra/http/client/client.factor | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extra/http/client/client.factor b/extra/http/client/client.factor index 8879a76a5c..cc356ca8e3 100755 --- a/extra/http/client/client.factor +++ b/extra/http/client/client.factor @@ -39,13 +39,16 @@ DEFER: http-request SYMBOL: redirects +: absolute-url? ( url -- ? ) + [ "http://" head? ] [ "https://" head? ] bi or ; + : do-redirect ( response -- response stream ) dup response-code 300 399 between? [ stdio get dispose redirects inc redirects get max-redirects < [ header>> "location" swap at - dup "http://" head? [ + dup absolute-url? [ absolute-redirect ] [ relative-redirect @@ -116,8 +119,12 @@ M: download-failed error. : download-to ( url file -- ) #! Downloads the contents of a URL to a file. - swap http-get-stream swap check-response - [ swap latin1 stream-copy ] with-disposal ; + swap http-get-stream check-response + dup string? [ + latin1 [ write ] with-file-writer + ] [ + [ swap latin1 stream-copy ] with-disposal + ] if ; : download ( url -- ) dup download-name download-to ;