Add timeout fine-tunning advanced docs section (#476)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add timeout fine-tunning advanced docs section * Rephrase part of timeout documentation
authored by Mateusz Woś · committed by Florimond Manca · parent 84731c8 · Browse files · 2 files·+75 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+75 added−0 removed
- other:+75 added−0 removed
Provenance
- Commit
2984499- Tree
fa289a8- Author
Mateusz Woś <wos.mateusz16@gmail.com>- Committer
Florimond Manca <florimond.manca@gmail.com>- Parent
84731c8
2 files changed+75 added−0 removed
modified:docs/advanced.md+73 added
165 unmodified lines166 167 # This request will be tunneled instead of forwarded.168 client.get("http://example.com")169 ```170+171+172+## Timeout fine-tuning173+HTTPX offers various request timeout management options. Three types of timeouts are available: **connect** timeouts, 174+**write** timeouts and **read** timeouts.175+176+* The **connect timeout** specifies the maximum amount of time to wait until a connection to the requested host is established. 177+If HTTPX is unable to connect within this time frame, a `ConnectTimeout` exception is raised.178+* The **write timeout** specifies the maximum duration to wait for a chunk of data to be sent (for example, a chunk of the request body). 179+If HTTPX is unable to send data within this time frame, a `WriteTimeout` exception is raised.180+* The **read timeout** specifies the maximum duration to wait for a chunk of data to be received (for example, a chunk of the response body). 181+If HTTPX is unable to receive data within this time frame, a `ReadTimeout` exception is raised.182+183+### Setting timeouts184+You can set timeouts on two levels:185+186+- For a given request:187+188+```python189+# Using top-level API190+httpx.get('http://example.com/api/v1/example', timeout=5)191+192+# Or, with a client:193+client = httpx.Client()194+client.get("http://example.com/api/v1/example", timeout=5)195+```196+197+- On a client instance, which results in the given `timeout` being used as a default for requests made with this client:198+199+```python200+client = httpx.Client(timeout=5)201+client.get('http://example.com/api/v1/example')202+```203+204+Besides, you can pass timeouts in two forms:205+206+- A number, which sets the read, write and connect timeouts to the same value, as in the examples above. 207+- A `TimeoutConfig` instance, which allows to define the read, write and connect timeouts independently:208+209+```python210+timeout = httpx.TimeoutConfig(211+ connect_timeout=5, 212+ read_timeout=10, 213+ write_timeout=15214+)215+216+resp = httpx.get('http://example.com/api/v1/example', timeout=timeout)217+```218+219+### Default timeouts220+By default all types of timeouts are set to 5 second.221+ 222+### Disabling timeouts223+To disable timeouts, you can pass `None` as a timeout parameter. 224+Note that currently this is not supported by the top-level API.225+226+```python227+url = "http://example.com/api/v1/delay/10"228+229+httpx.get(url, timeout=None) # Times out after 5s230+231+232+client = httpx.Client(timeout=None)233+client.get(url) # Does not timeout, returns after 10s234+235+236+timeout = httpx.TimeoutConfig(237+ connect_timeout=5, 238+ read_timeout=None, 239+ write_timeout=5240+)241+httpx.get(url, timeout=timeout) # Does not timeout, returns after 10s242+```modified:docs/quickstart.md+2 added
378 unmodified lines379 ```python380 >>> httpx.get('https://github.com/', timeout=0.001)381 ```382 383+For advanced timeout management, see [Timeout fine-tuning](https://www.encode.io/httpx/advanced/#timeout-fine-tuning).384+385 ## Authentication386 387 HTTPX supports Basic and Digest HTTP authentication.388 18 unmodified lines