Skip to content

Commit

Permalink
Update documentation: complete client docs for honoring proxy env vars (
Browse files Browse the repository at this point in the history
aio-libs#7235)

<!-- Thank you for your contribution! -->

## What do these changes do?

* Update proxy support docs to honor `no_proxy` env
* Complete `trust_env` parameter description to honor `wss_proxy`,
`ws_proxy` or `no_proxy` env

## Are there changes in behavior for the user?

No

## Related issue number

Update docs for: aio-libs#4431

## Checklist

- [ ] I think the code is well written
- [ ] Unit tests for the changes exist
- [x] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names.
- [ ] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating
the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
* `.misc`: A ticket has been closed, but it is not of interest to users.
* Make sure to use full sentences with correct case and punctuation, for
example: "Fix issue with non-ascii contents in doctest text files."

---------

Co-authored-by: Marcel Loop <[email protected]>
Co-authored-by: Sam Bull <[email protected]>
  • Loading branch information
3 people authored Apr 16, 2023
1 parent ae7703c commit 1c49738
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/7325.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Complete trust_env parameter description to honor wss_proxy, ws_proxy or no_proxy env
12 changes: 9 additions & 3 deletions docs/client_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ DER with e.g::
to :class:`TCPConnector` as default, the value from
:meth:`ClientSession.get` and others override default.

.. _aiohttp-client-proxy-support:

Proxy support
-------------

Expand Down Expand Up @@ -592,14 +594,18 @@ Authentication credentials can be passed in proxy URL::
Contrary to the ``requests`` library, it won't read environment
variables by default. But you can do so by passing
``trust_env=True`` into :class:`aiohttp.ClientSession`
constructor for extracting proxy configuration from
*HTTP_PROXY*, *HTTPS_PROXY*, *WS_PROXY* or *WSS_PROXY* *environment
variables* (all are case insensitive)::
constructor.::

async with aiohttp.ClientSession(trust_env=True) as session:
async with session.get("http://python.org") as resp:
print(resp.status)

.. note::
aiohttp uses :func:`urllib.request.getproxies`
for reading the proxy configuration (e.g. from the *HTTP_PROXY* etc. environment variables) and applies them for the *HTTP*, *HTTPS*, *WS* and *WSS* schemes.

Hosts defined in ``no_proxy`` will bypass the proxy.

Proxy credentials are given from ``~/.netrc`` file if present (see
:class:`aiohttp.ClientSession` for more details).

Expand Down
11 changes: 6 additions & 5 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ The client session supports the context manager protocol for self closing.

.. versionadded:: 3.7

:param bool trust_env: Get proxies information from *HTTP_PROXY* /
*HTTPS_PROXY* environment variables if the parameter is ``True``
(``False`` by default).
:param bool trust_env: Trust environment settings for proxy configuration if the parameter
is ``True`` (``False`` by default). See :ref:`aiohttp-client-proxy-support` for
more information.

Get proxy credentials from ``~/.netrc`` file if present.

Expand Down Expand Up @@ -321,8 +321,9 @@ The client session supports the context manager protocol for self closing.

.. attribute:: trust_env

Should get proxies information from HTTP_PROXY / HTTPS_PROXY environment
variables or ~/.netrc file if present
Trust environment settings for proxy configuration
or ~/.netrc file if present. See :ref:`aiohttp-client-proxy-support` for
more information.

:class:`bool` default is ``False``

Expand Down

0 comments on commit 1c49738

Please sign in to comment.