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
locals-and-roots
Jon Harper 2016-03-31 13:01:07 +02:00 committed by John Benediktsson
parent 9cbf548340
commit ed33bc7862
2 changed files with 17 additions and 2 deletions

View File

@ -208,3 +208,14 @@ CONSTANT: classic-proxy-settings H{
"http://www.google.com" "GET" <client-request> ?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

View File

@ -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 ;
: <client-request> ( url method -- request )
<request>