]> gitweb.factorcode.org Git - factor.git/commitdiff
http.client: throw if the proxy not empty and not valid
authorJon Harper <jon.harper87@gmail.com>
Wed, 30 Mar 2016 21:10:55 +0000 (23:10 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Mar 2016 13:25:03 +0000 (06:25 -0700)
basis/http/client/client-docs.factor
basis/http/client/client-tests.factor
basis/http/client/client.factor
basis/http/http-docs.factor

index c5f4fac84a7a5e5ce7428ae707f5bc4c1c18e5d4..3335067852ec75393aa943003c57b98995d5aff7 100644 (file)
@@ -10,6 +10,9 @@ HELP: download-failed
 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." }
index 5006999711dfc608cbd48a1392d3dc2f378484af..7cda571681e84b214d9484b93904a7cdc12a2088 100644 (file)
@@ -202,3 +202,9 @@ CONSTANT: classic-proxy-settings H{
        "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
index 19ca7c0c9fd9b7b2e127ee14c070daccf83bfc69..57c32785f508f949d0cb7159e991f910e6cbaa47 100644 (file)
@@ -11,6 +11,7 @@ environment ;
 IN: http.client
 
 ERROR: too-many-redirects ;
+ERROR: invalid-proxy proxy ;
 
 : success? ( code -- ? ) 200 299 between? ;
 
@@ -181,8 +182,15 @@ SYMBOL: redirects
        [ "." 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 )
index 340098ec63b064571d8129a8769a2933ddab4772..b8a726331f9215ee362ea4bc9723c6c953e4197f 100644 (file)
@@ -204,7 +204,7 @@ ARTICLE: "http.proxy-variables" "HTTP(S) proxy variables"
 { "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" }