Skip to content
Myr

Document 'target' extension (#3160)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 392dbe4 · Browse files · 1 file+41 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

1 file+41 added−0 removed

  • other:+41 added−0 removed

1 file+41 added−0 removed

modified:docs/advanced/extensions.md+41 added
136 unmodified lines
137```138139This extension is how the `httpx` timeouts are implemented, ensuring that the timeout values are associated with the request instance and passed throughout the stack. You shouldn't typically be working with this extension directly, but use the higher level `timeout` API instead.140141### `"target"`142143The target that is used as [the HTTP target instead of the URL path](https://datatracker.ietf.org/doc/html/rfc2616#section-5.1.2).144145This enables support constructing requests that would otherwise be unsupported.146147* URL paths with non-standard escaping applied.148* Forward proxy requests using an absolute URI.149* Tunneling proxy requests using `CONNECT` with hostname as the target.150* Server-wide `OPTIONS *` requests.151152Some examples:153154Using the 'target' extension to send requests without the standard path escaping rules...155156```python157# Typically a request to "https://www.example.com/test^path" would158# connect to "www.example.com" and send an HTTP/1.1 request like...159#160# GET /test%5Epath HTTP/1.1161#162# Using the target extension we can include the literal '^'...163#164# GET /test^path HTTP/1.1165#166# Note that requests must still be valid HTTP requests.167# For example including whitespace in the target will raise a `LocalProtocolError`.168extensions = {"target": b"/test^path"}169response = httpx.get("https://www.example.com", extensions=extensions)170```171172The `target` extension also allows server-wide `OPTIONS *` requests to be constructed...173174```python175# This will send the following request...176#177# CONNECT * HTTP/1.1178extensions = {"target": b"*"}179response = httpx.request("CONNECT", "https://www.example.com", extensions=extensions)180```181182## Response Extensions183184### `"http_version"`185
57 unmodified lines