Force HTTP/1.1 on short-lived connections (#284)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Seth Michael Larson · committed by GitHub · parent 8ea32e6 · Browse files · 5 files·+13 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+13 added−6 removed
- tests:+1 added−0 removed
- other:+12 added−6 removed
Provenance
- Commit
e7aa6d6- Tree
455cb36- Author
Seth Michael Larson <sethmichaellarson@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
8ea32e6
5 files changed+13 added−6 removed
modified:docs/api.md+8 added-2 removed
123345678910111213143 unmodified lines18192021162223242526127 unmodified linesExpand all# Developer Interface
## Main Interface## Helper Functions
!!! note Only use these functions if you're testing HTTPX in a console or making a small number of requests. Using a `Client` will enable HTTP/2 and connection pooling for more efficient and long-lived connections.
* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`* `post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`3 unmodified lines* `request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
## `Client`
*An HTTP client, with connection pooling, redirects, cookie persistence, etc.**An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*
```python>>> client = httpx.Client()>>> response = client.get('https://example.org')127 unmodified linesExpand allmodified:docs/index.md+1 added-1 removed
38 unmodified lines39 <Response [200 OK]>40 >>> r.status_code41 20042 >>> r.http_version43-'HTTP/2'43+'HTTP/1.1'44 >>> r.headers['content-type']45 'text/html; charset=UTF-8'46 >>> r.text47 '<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'68 unmodified linesmodified:httpx/api.py+1 added-1 removed
31 unmodified lines32 verify: VerifyTypes = True,33 stream: bool = False,34 trust_env: bool = None,35 ) -> Response:36- with Client() as client:36+ with Client(http_versions=["HTTP/1.1"]) as client:37 return client.request(38 method=method,39 url=url,40 data=data,247 unmodified linesmodified:tests/test_api.py+1 added
27 unmodified lines28 response = httpx.get("http://127.0.0.1:8000/")29 assert response.status_code == 20030 assert response.reason_phrase == "OK"31 assert response.text == "Hello, world!"32+ assert response.http_version == "HTTP/1.1"33 34 35 @threadpool36 def test_post(server):56 unmodified linesmodified:README.md+2 added-2 removed
27 unmodified lines28 >>> r29 <Response [200 OK]>30 >>> r.status_code31 20032->>> r.protocol33-'HTTP/2'32+>>> r.http_version33+'HTTP/1.1'34 >>> r.headers['content-type']35 'text/html; charset=UTF-8'36 >>> r.text37 '<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'77 unmodified lines