From b2b9ff93c7607ce10bcb3d5c571d2d11168a8ee6 Mon Sep 17 00:00:00 2001 From: cdeler Date: Fri, 4 Sep 2020 15:17:36 +0300 Subject: [PATCH 1/4] Edited documentation about proxy-envs usage (#404) --- docs/environment_variables.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 5f99522c10..05e18dbabf 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -139,18 +139,31 @@ Example: SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')" ``` -`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` +`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY` ---------------------------------------- Valid values: A URL to a proxy -Sets the proxy to be used for `http`, `https`, or all requests respectively. +`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` set the proxy to be used for `http`, `https`, or all requests respectively. + +`NO_PROXY` disables the proxy for specific urls ```bash -export HTTP_PROXY=http://127.0.0.1:3080 +export HTTP_PROXY=http://my-external-proxy.com:1234 +export NO_PROXY=http://127.0.0.1,python-httpx.org # This request will be sent through the proxy python -c "import httpx; httpx.get('http://example.com')" + +# This request will be sent directly, bypassing the proxy +python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')" +python -c "import httpx; httpx.get('https://www.python-httpx.org')" + +# This request will be sent directly, as we set `trus_env=False` +python -c "import httpx; httpx.get('http://example.com', trust_env=False)" ``` For more information on using proxies in HTTPX, see [HTTP Proxying](/advanced/#http-proxying). + +The other tools compatible with these variables convention: [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables), +[requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies). From 84848269b6fe3f9417722c1f865f7f24cbe31c30 Mon Sep 17 00:00:00 2001 From: cdeler Date: Sat, 5 Sep 2020 09:44:20 +0300 Subject: [PATCH 2/4] PR review (#404) Co-authored-by: Florimond Manca --- docs/environment_variables.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 05e18dbabf..4a71ce9727 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -155,7 +155,7 @@ export NO_PROXY=http://127.0.0.1,python-httpx.org # This request will be sent through the proxy python -c "import httpx; httpx.get('http://example.com')" -# This request will be sent directly, bypassing the proxy +# These requests will be sent directly, bypassing the proxy python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')" python -c "import httpx; httpx.get('https://www.python-httpx.org')" @@ -165,5 +165,7 @@ python -c "import httpx; httpx.get('http://example.com', trust_env=False)" For more information on using proxies in HTTPX, see [HTTP Proxying](/advanced/#http-proxying). -The other tools compatible with these variables convention: [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables), -[requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies). +These environment variables are used as a convention by various HTTP tooling, including: + +* [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables) +* [requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies) From 0bbd8c58e5cfe80cc068545240fcea50539d63d5 Mon Sep 17 00:00:00 2001 From: cdeler Date: Sat, 5 Sep 2020 17:29:54 +0300 Subject: [PATCH 3/4] PR review (#404) Co-authored-by: Florimond Manca --- docs/environment_variables.md | 37 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 6ef88b5ab7..9381a3a84d 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -134,32 +134,47 @@ Example: SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')" ``` -## `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY` +## Proxies + +The environment variables documented below are used as a convention by various HTTP tooling, including: + +* [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables) +* [requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies) + +For more information on using proxies in HTTPX, see [HTTP Proxying](/advanced/#http-proxying). + +### `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` Valid values: A URL to a proxy `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` set the proxy to be used for `http`, `https`, or all requests respectively. +```bash +export HTTP_PROXY=http://my-external-proxy.com:1234 + +# This request will be sent through the proxy +python -c "import httpx; httpx.get('http://example.com')" + +# This request will be sent directly, as we set `trus_env=False` +python -c "import httpx; httpx.get('http://example.com', trust_env=False)" + +``` + +### `NO_PROXY` + +Valid values: a comma-separated list of hostnames/urls + `NO_PROXY` disables the proxy for specific urls ```bash export HTTP_PROXY=http://my-external-proxy.com:1234 export NO_PROXY=http://127.0.0.1,python-httpx.org -# This request will be sent through the proxy +# As in the previous example, this request will be sent through the proxy python -c "import httpx; httpx.get('http://example.com')" # These requests will be sent directly, bypassing the proxy python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')" python -c "import httpx; httpx.get('https://www.python-httpx.org')" - -# This request will be sent directly, as we set `trus_env=False` -python -c "import httpx; httpx.get('http://example.com', trust_env=False)" ``` -For more information on using proxies in HTTPX, see [HTTP Proxying](/advanced/#http-proxying). - -These environment variables are used as a convention by various HTTP tooling, including: - -* [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables) -* [requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies) From 9195174628610a14d827c6b74354b74e1c7d957e Mon Sep 17 00:00:00 2001 From: Florimond Manca Date: Sun, 6 Sep 2020 13:42:08 +0200 Subject: [PATCH 4/4] Fix typo --- docs/environment_variables.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 9381a3a84d..252ab66c74 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -155,7 +155,7 @@ export HTTP_PROXY=http://my-external-proxy.com:1234 # This request will be sent through the proxy python -c "import httpx; httpx.get('http://example.com')" -# This request will be sent directly, as we set `trus_env=False` +# This request will be sent directly, as we set `trust_env=False` python -c "import httpx; httpx.get('http://example.com', trust_env=False)" ``` @@ -177,4 +177,3 @@ python -c "import httpx; httpx.get('http://example.com')" python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')" python -c "import httpx; httpx.get('https://www.python-httpx.org')" ``` -