Skip to content

Commit

Permalink
Add timeout argument to aiohttp.client.request and bypass it to Clien…
Browse files Browse the repository at this point in the history
…tSession

PR #3213 by @knight42

* feat: specify timeout in aiohttp.request

* doc: add myself to contributors

* doc: add 3213.feature in CHANGES
  • Loading branch information
knight42 authored and webknjaz committed Aug 31, 2018
1 parent 8c49f00 commit 03d83b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/3213.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable users to set `ClientTimeout` in `aiohttp.request`
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Jashandeep Sohi
Jeongkyu Shin
Jeroen van der Heijden
Jesus Cea
Jian Zeng
Jinkyu Yi
Joel Watts
Jon Nabozny
Expand Down
5 changes: 4 additions & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ def request(method, url, *,
connector=None,
loop=None,
read_until_eof=True,
timeout=sentinel,
proxy=None,
proxy_auth=None) -> _SessionRequestContextManager:
"""Constructs and sends a request. Returns response object.
Expand Down Expand Up @@ -933,6 +934,8 @@ def request(method, url, *,
read_until_eof - Read response until eof if response
does not have Content-Length header.
loop - Optional event loop.
timeout - Optional ClientTimeout settings structure, 5min
total timeout by default.
Usage::
>>> import aiohttp
>>> resp = await aiohttp.request('GET', 'http://python.org/')
Expand All @@ -946,7 +949,7 @@ def request(method, url, *,
connector = TCPConnector(loop=loop, force_close=True)

session = ClientSession(
loop=loop, cookies=cookies, version=version,
loop=loop, cookies=cookies, version=version, timeout=timeout,
connector=connector, connector_owner=connector_owner)

return _SessionRequestContextManager(
Expand Down
5 changes: 4 additions & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ certification chaining.
version=HttpVersion(major=1, minor=1), \
compress=None, chunked=None, expect100=False, raise_for_status=None, \
connector=None, loop=None,\
read_until_eof=True)
read_until_eof=True, timeout=sentinel)

:async-with:

Expand Down Expand Up @@ -719,6 +719,9 @@ certification chaining.
does not have Content-Length header.
``True`` by default (optional).

:param timeout: a :class:`ClientTimeout` settings structure, 5min
total timeout by default.

:param loop: :ref:`event loop<asyncio-event-loop>`
used for processing HTTP requests.
If param is ``None``, :func:`asyncio.get_event_loop`
Expand Down

0 comments on commit 03d83b0

Please sign in to comment.