Force HTTP/1.1 on short-lived connections (#284)

This commit is contained in:
Seth Michael Larson 2019-08-27 07:54:11 -05:00 committed by GitHub
parent 8ea32e647f
commit e7aa6d6710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 6 deletions

View File

@ -29,8 +29,8 @@ Let's get started...
<Response [200 OK]>
>>> r.status_code
200
>>> r.protocol
'HTTP/2'
>>> r.http_version
'HTTP/1.1'
>>> r.headers['content-type']
'text/html; charset=UTF-8'
>>> r.text

View File

@ -1,6 +1,12 @@
# 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])`
@ -13,7 +19,7 @@
## `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()

View File

@ -40,7 +40,7 @@ Let's get started...
>>> r.status_code
200
>>> r.http_version
'HTTP/2'
'HTTP/1.1'
>>> r.headers['content-type']
'text/html; charset=UTF-8'
>>> r.text

View File

@ -33,7 +33,7 @@ def request(
stream: bool = False,
trust_env: bool = None,
) -> Response:
with Client() as client:
with Client(http_versions=["HTTP/1.1"]) as client:
return client.request(
method=method,
url=url,

View File

@ -29,6 +29,7 @@ def test_get(server):
assert response.status_code == 200
assert response.reason_phrase == "OK"
assert response.text == "Hello, world!"
assert response.http_version == "HTTP/1.1"
@threadpool