From 2ac1942c72fda6d2a1912fb4e8b6ebfc43ee9f30 Mon Sep 17 00:00:00 2001 From: ERAMOTO Masaya Date: Mon, 19 Dec 2016 16:27:24 +0900 Subject: url: --noproxy option overrides NO_PROXY environment variable Under condition using http_proxy env var, noproxy list was the combination of --noproxy option and NO_PROXY env var previously. Since this commit, --noproxy option overrides NO_PROXY environment variable even if use http_proxy env var. Closes #1140 --- docs/cmdline-opts/noproxy.d | 4 ++++ docs/cmdline-opts/page-footer | 10 ++++++++ lib/url.c | 3 +-- tests/data/Makefile.inc | 1 + tests/data/test1252 | 52 +++++++++++++++++++++++++++++++++++++++++ tests/data/test1253 | 53 ++++++++++++++++++++++++++++++++++++++++++ tests/data/test1254 | 53 ++++++++++++++++++++++++++++++++++++++++++ tests/data/test1255 | 53 ++++++++++++++++++++++++++++++++++++++++++ tests/data/test1256 | 54 +++++++++++++++++++++++++++++++++++++++++++ tests/data/test1257 | 54 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 335 insertions(+), 2 deletions(-) create mode 100644 tests/data/test1252 create mode 100644 tests/data/test1253 create mode 100644 tests/data/test1254 create mode 100644 tests/data/test1255 create mode 100644 tests/data/test1256 create mode 100644 tests/data/test1257 diff --git a/docs/cmdline-opts/noproxy.d b/docs/cmdline-opts/noproxy.d index 4f06d9f5d..e0d2d598c 100644 --- a/docs/cmdline-opts/noproxy.d +++ b/docs/cmdline-opts/noproxy.d @@ -9,3 +9,7 @@ effectively disables the proxy. Each name in this list is matched as either a domain which contains the hostname, or the hostname itself. For example, local.com would match local.com, local.com:80, and www.local.com, but not www.notlocal.com. + +Since 7.52.2, This option overrides the environment variables that disable +the proxy. If there's an environment variable disabling a proxy, you can set +noproxy list to \&"" to override it. diff --git a/docs/cmdline-opts/page-footer b/docs/cmdline-opts/page-footer index 94412c703..c7b1ae014 100644 --- a/docs/cmdline-opts/page-footer +++ b/docs/cmdline-opts/page-footer @@ -23,6 +23,16 @@ Sets the proxy server to use if no protocol-specific proxy is set. .IP "NO_PROXY " list of host names that shouldn't go through any proxy. If set to a asterisk \&'*' only, it matches all hosts. + +Since 7.52.2, this environment variable disable the proxy even if specify +--proxy option. That is +.B NO_PROXY=direct.example.com curl -x http://proxy.example.com +.B http://direct.example.com +accesses the target URL directly, and +.B NO_PROXY=direct.example.com curl -x http://proxy.example.com +.B http://somewhere.example.com +accesses the target URL through proxy. + .SH "PROXY PROTOCOL PREFIXES" Since curl version 7.21.7, the proxy string may be specified with a protocol:// prefix to specify alternative proxy protocols. diff --git a/lib/url.c b/lib/url.c index d1a7afe1d..1f6e5bed9 100644 --- a/lib/url.c +++ b/lib/url.c @@ -6252,8 +6252,7 @@ static CURLcode create_conn(struct Curl_easy *data, else if(!proxy && !socksproxy) #ifndef CURL_DISABLE_HTTP /* if the host is not in the noproxy list, detect proxy. */ - if(!check_noproxy(conn->host.name, no_proxy)) - proxy = detect_proxy(conn); + proxy = detect_proxy(conn); #else /* !CURL_DISABLE_HTTP */ proxy = NULL; #endif /* CURL_DISABLE_HTTP */ diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index afad1984d..471eb2510 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -128,6 +128,7 @@ test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 \ test1228 test1229 test1230 test1231 test1232 test1233 test1234 test1235 \ test1236 test1237 test1238 test1239 test1240 test1241 test1242 test1243 \ test1244 test1245 test1246 test1247 test1248 test1249 test1250 test1251 \ +test1252 test1253 test1254 test1255 test1256 test1257 \ \ test1280 test1281 test1282 \ \ diff --git a/tests/data/test1252 b/tests/data/test1252 new file mode 100644 index 000000000..cbaef48b7 --- /dev/null +++ b/tests/data/test1252 @@ -0,0 +1,52 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using --proxy, override NO_PROXY by --nproxy and access target URL directly + + +NO_PROXY=example.com + + +http://%HOSTIP:%HTTPPORT/1252 --proxy http://%HOSTIP:%HTTPPORT --noproxy %HOSTIP + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET /1252 HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +Accept: */* + + + + diff --git a/tests/data/test1253 b/tests/data/test1253 new file mode 100644 index 000000000..74002994b --- /dev/null +++ b/tests/data/test1253 @@ -0,0 +1,53 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using --proxy, override NO_PROXY by --nproxy and access target URL through proxy + + +NO_PROXY=example.com + + +http://somewhere.example.com/1253 --proxy http://%HOSTIP:%HTTPPORT --noproxy %HOSTIP + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET http://somewhere.example.com/1253 HTTP/1.1 +Host: somewhere.example.com +Accept: */* +Proxy-Connection: Keep-Alive + + + + diff --git a/tests/data/test1254 b/tests/data/test1254 new file mode 100644 index 000000000..817b9342b --- /dev/null +++ b/tests/data/test1254 @@ -0,0 +1,53 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using --proxy, override NO_PROXY by --nproxy and access target URL through proxy + + +NO_PROXY=example.com + + +http://somewhere.example.com/1254 --proxy http://%HOSTIP:%HTTPPORT --noproxy "" + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET http://somewhere.example.com/1254 HTTP/1.1 +Host: somewhere.example.com +Accept: */* +Proxy-Connection: Keep-Alive + + + + diff --git a/tests/data/test1255 b/tests/data/test1255 new file mode 100644 index 000000000..d82310f67 --- /dev/null +++ b/tests/data/test1255 @@ -0,0 +1,53 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using http_proxy, override NO_PROXY by --nproxy and access target URL directly + + +http_proxy=http://%HOSTIP:%HTTPPORT +NO_PROXY=example.com + + +http://%HOSTIP:%HTTPPORT/1255 --noproxy %HOSTIP + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET /1255 HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +Accept: */* + + + + diff --git a/tests/data/test1256 b/tests/data/test1256 new file mode 100644 index 000000000..09c59f4ff --- /dev/null +++ b/tests/data/test1256 @@ -0,0 +1,54 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using http_proxy, override NO_PROXY by --nproxy and access target URL through proxy + + +http_proxy=http://%HOSTIP:%HTTPPORT +NO_PROXY=example.com + + +http://somewhere.example.com/1256 --noproxy %HOSTIP + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET http://somewhere.example.com/1256 HTTP/1.1 +Host: somewhere.example.com +Accept: */* +Proxy-Connection: Keep-Alive + + + + diff --git a/tests/data/test1257 b/tests/data/test1257 new file mode 100644 index 000000000..6b7e93736 --- /dev/null +++ b/tests/data/test1257 @@ -0,0 +1,54 @@ + + + +HTTP +HTTP proxy +NO_PROXY +noproxy + + + +# Server-side + + +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 4 +Content-Type: text/html + +foo + + + +# Client-side + + +http + + +Under condition using http_proxy, override NO_PROXY by --nproxy and access target URL through proxy + + +http_proxy=http://%HOSTIP:%HTTPPORT +NO_PROXY=example.com + + +http://somewhere.example.com/1257 --noproxy "" + + + +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +GET http://somewhere.example.com/1257 HTTP/1.1 +Host: somewhere.example.com +Accept: */* +Proxy-Connection: Keep-Alive + + + + -- cgit v1.2.1