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
"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
[ 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>