From ed33bc786263936342b03963ed603bf32985fad5 Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Thu, 31 Mar 2016 13:01:07 +0200 Subject: [PATCH] http.client, request-url don't try to fix unfixable urls Before, it would prepend http:// to anything and that would create bad urls like URL" http://http://". It's simpler to fix only what is fixable --- basis/http/client/client-tests.factor | 11 +++++++++++ basis/http/client/client.factor | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/basis/http/client/client-tests.factor b/basis/http/client/client-tests.factor index 7cda571681..0f4a36fb7b 100644 --- a/basis/http/client/client-tests.factor +++ b/basis/http/client/client-tests.factor @@ -208,3 +208,14 @@ CONSTANT: classic-proxy-settings H{ "http://www.google.com" "GET" ?default-proxy ] with-variable ] [ invalid-proxy? ] must-fail-with + +! This url is misparsed bu request-url can fix it +{ T{ url + { protocol "http" } + { host "www.google.com" } + { path "/" } + { port 80 } +} } [ "www.google.com" request-url ] unit-test + +! This one is not fixable, leave it as it is +{ T{ url } } [ "" request-url ] unit-test diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor index 57c32785f5..b439d31384 100644 --- a/basis/http/client/client.factor +++ b/basis/http/client/client.factor @@ -237,11 +237,15 @@ SYMBOL: redirects [ do-redirect ] [ nip ] if ] with-variable ; inline recursive +: misparsed-url? ( url -- url' ) + [ protocol>> not ] [ host>> not ] [ path>> ] + tri and and ; + : request-url ( url -- url' ) - dup >url dup protocol>> [ nip ] [ + dup >url dup misparsed-url? [ drop dup url? [ present ] when "http://" prepend >url - ] if ensure-port ; + ] [ nip ] if ensure-port ; : ( url method -- request )