From: Seth Michael Larson Date: Tue, 27 Aug 2019 12:54:11 +0000 (-0500) Subject: Force HTTP/1.1 on short-lived connections (#284) X-Git-Tag: 0.7.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7aa6d67109b33eab5d3fbac0dead4c74c26167e;p=thirdparty%2Fhttpx.git Force HTTP/1.1 on short-lived connections (#284) --- diff --git a/README.md b/README.md index c8f68d77..1180ae8a 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ Let's get started... >>> 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 diff --git a/docs/api.md b/docs/api.md index 5749b3ee..125c687e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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() diff --git a/docs/index.md b/docs/index.md index 06a96f60..949de825 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/httpx/api.py b/httpx/api.py index fe52e14e..60d9ea76 100644 --- a/httpx/api.py +++ b/httpx/api.py @@ -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, diff --git a/tests/test_api.py b/tests/test_api.py index 7f636f3e..de4267c7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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