HELP: too-many-redirects
{ $error-description "Thrown by " { $link http-request } " if the server returns a chain of than " { $link max-redirects } " redirections." } ;
+HELP: invalid-proxy
+{ $error-description "Thrown by " { $link http-request } " if the proxy url is not valid." } ;
+
HELP: <get-request>
{ $values { "url" { $or url string } } { "request" request } }
{ $description "Constructs an HTTP GET request for retrieving the URL." }
"allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
] with-variables
] unit-test
+
+[
+ <url> 3128 >>port "http.proxy" [
+ "http://www.google.com" "GET" <client-request> ?default-proxy
+ ] with-variable
+] [ invalid-proxy? ] must-fail-with
IN: http.client
ERROR: too-many-redirects ;
+ERROR: invalid-proxy proxy ;
: success? ( code -- ? ) 200 299 between? ;
[ "." split no-proxy-match? ] with any?
] [ drop f ] if* ;
+: (check-proxy) ( proxy -- ? )
+ {
+ { [ dup URL" " = ] [ drop f ] }
+ { [ dup host>> ] [ drop t ] }
+ [ invalid-proxy ]
+ } cond ;
+
: check-proxy ( request proxy -- request' )
- dup [ host>> ] [ f ] if*
+ dup [ (check-proxy) ] [ f ] if*
[ drop f ] unless [ clone ] dip >>proxy-url ;
: get-default-proxy ( request -- default-proxy )
{ "HTTPS" { $snippet "\"https.proxy\"" } "https_proxy" "HTTPS_PROXY" }
{ "no proxy" { $snippet "\"no_proxy\"" } "no_proxy" "NO_PROXY" }
}
-"When making an http request, if the target host is not matched by the no_proxy list, the " { $vocab-link "http.client" } " will fill the missing components of the " { $slot "proxy-url" } " slot of the " { $link request } " from the value of these variables."
+"When making an http request, if the target host is not matched by the no_proxy list, the " { $vocab-link "http.client" } " will fill the missing components of the " { $slot "proxy-url" } " slot of the " { $link request } " from the value of these variables. If the filled result is not valid, an error is thrown."
{ $notes "The dynamic variables are keyed by strings. This allows to use Factor's command line support to define them (see in the examples below)." }
{ $heading "no_proxy" }