From 9cbf5483409c075351b675cba374ea4c3496aae1 Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Wed, 30 Mar 2016 23:10:55 +0200 Subject: [PATCH] http.client: throw if the proxy not empty and not valid --- basis/http/client/client-docs.factor | 3 +++ basis/http/client/client-tests.factor | 6 ++++++ basis/http/client/client.factor | 10 +++++++++- basis/http/http-docs.factor | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/basis/http/client/client-docs.factor b/basis/http/client/client-docs.factor index c5f4fac84a..3335067852 100644 --- a/basis/http/client/client-docs.factor +++ b/basis/http/client/client-docs.factor @@ -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: { $values { "url" { $or url string } } { "request" request } } { $description "Constructs an HTTP GET request for retrieving the URL." } diff --git a/basis/http/client/client-tests.factor b/basis/http/client/client-tests.factor index 5006999711..7cda571681 100644 --- a/basis/http/client/client-tests.factor +++ b/basis/http/client/client-tests.factor @@ -202,3 +202,9 @@ CONSTANT: classic-proxy-settings H{ "allprivate.google.com" "GET" ?default-proxy proxy-url>> ] with-variables ] unit-test + +[ + 3128 >>port "http.proxy" [ + "http://www.google.com" "GET" ?default-proxy + ] with-variable +] [ invalid-proxy? ] must-fail-with diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor index 19ca7c0c9f..57c32785f5 100644 --- a/basis/http/client/client.factor +++ b/basis/http/client/client.factor @@ -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 ) diff --git a/basis/http/http-docs.factor b/basis/http/http-docs.factor index 340098ec63..b8a726331f 100644 --- a/basis/http/http-docs.factor +++ b/basis/http/http-docs.factor @@ -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" }