From: Tom Christie Date: Tue, 20 Aug 2019 14:15:38 +0000 (+0100) Subject: Response.protocol -> Response.http_version (#250) X-Git-Tag: 0.7.2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1ec1c33cddc683101ffb046dfb418a9a62cf12b;p=thirdparty%2Fhttpx.git Response.protocol -> Response.http_version (#250) * Response.protocol -> Response.http_version * Update docs --- diff --git a/docs/api.md b/docs/api.md index f5286dd0..5749b3ee 100644 --- a/docs/api.md +++ b/docs/api.md @@ -39,7 +39,7 @@ * `def __init__(...)` * `.status_code` - **int** * `.reason_phrase` - **str** -* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"` +* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"` * `.url` - **URL** * `.headers` - **Headers** * `.content` - **bytes** diff --git a/docs/index.md b/docs/index.md index 40813c63..06a96f60 100644 --- a/docs/index.md +++ b/docs/index.md @@ -39,7 +39,7 @@ Let's get started... >>> r.status_code 200 ->>> r.protocol +>>> r.http_version 'HTTP/2' >>> r.headers['content-type'] 'text/html; charset=UTF-8' diff --git a/httpx/client.py b/httpx/client.py index ae75f15d..feeaee09 100644 --- a/httpx/client.py +++ b/httpx/client.py @@ -719,7 +719,7 @@ class Client(BaseClient): response = Response( status_code=async_response.status_code, - protocol=async_response.protocol, + http_version=async_response.http_version, headers=async_response.headers, content=sync_content, on_close=sync_on_close, diff --git a/httpx/dispatch/asgi.py b/httpx/dispatch/asgi.py index e3b4b0a0..01313fed 100644 --- a/httpx/dispatch/asgi.py +++ b/httpx/dispatch/asgi.py @@ -142,7 +142,7 @@ class ASGIDispatch(AsyncDispatcher): return AsyncResponse( status_code=status_code, - protocol="HTTP/1.1", + http_version="HTTP/1.1", headers=headers, content=response_body.iterate(), on_close=on_close, diff --git a/httpx/dispatch/http11.py b/httpx/dispatch/http11.py index eff419a1..46d7309c 100644 --- a/httpx/dispatch/http11.py +++ b/httpx/dispatch/http11.py @@ -54,7 +54,7 @@ class HTTP11Connection: return AsyncResponse( status_code=status_code, - protocol=http_version, + http_version=http_version, headers=headers, content=content, on_close=self.response_closed, diff --git a/httpx/dispatch/http2.py b/httpx/dispatch/http2.py index f9325982..199ee8fa 100644 --- a/httpx/dispatch/http2.py +++ b/httpx/dispatch/http2.py @@ -51,7 +51,7 @@ class HTTP2Connection: return AsyncResponse( status_code=status_code, - protocol="HTTP/2", + http_version="HTTP/2", headers=headers, content=content, on_close=on_close, diff --git a/httpx/dispatch/threaded.py b/httpx/dispatch/threaded.py index e4fdfd5e..60200109 100644 --- a/httpx/dispatch/threaded.py +++ b/httpx/dispatch/threaded.py @@ -64,7 +64,7 @@ class ThreadedDispatcher(AsyncDispatcher): return AsyncResponse( status_code=sync_response.status_code, - protocol=sync_response.protocol, + http_version=sync_response.http_version, headers=sync_response.headers, content=async_content, on_close=async_on_close, diff --git a/httpx/dispatch/wsgi.py b/httpx/dispatch/wsgi.py index 60e0a18c..e1109c05 100644 --- a/httpx/dispatch/wsgi.py +++ b/httpx/dispatch/wsgi.py @@ -104,7 +104,7 @@ class WSGIDispatch(Dispatcher): return Response( status_code=int(seen_status.split()[0]), - protocol="HTTP/1.1", + http_version="HTTP/1.1", headers=seen_response_headers, content=(chunk for chunk in result), on_close=getattr(result, "close", None), diff --git a/httpx/models.py b/httpx/models.py index edb5723f..4016f89a 100644 --- a/httpx/models.py +++ b/httpx/models.py @@ -688,13 +688,13 @@ class BaseResponse: self, status_code: int, *, - protocol: str = None, + http_version: str = None, headers: HeaderTypes = None, request: BaseRequest = None, on_close: typing.Callable = None, ): self.status_code = status_code - self.protocol = protocol + self.http_version = http_version self.headers = Headers(headers) self.request = request @@ -870,7 +870,7 @@ class AsyncResponse(BaseResponse): self, status_code: int, *, - protocol: str = None, + http_version: str = None, headers: HeaderTypes = None, content: AsyncResponseContent = None, on_close: typing.Callable = None, @@ -879,7 +879,7 @@ class AsyncResponse(BaseResponse): ): super().__init__( status_code=status_code, - protocol=protocol, + http_version=http_version, headers=headers, request=request, on_close=on_close, @@ -960,7 +960,7 @@ class Response(BaseResponse): self, status_code: int, *, - protocol: str = None, + http_version: str = None, headers: HeaderTypes = None, content: ResponseContent = None, on_close: typing.Callable = None, @@ -969,7 +969,7 @@ class Response(BaseResponse): ): super().__init__( status_code=status_code, - protocol=protocol, + http_version=http_version, headers=headers, request=request, on_close=on_close, diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index b037085f..e4e62747 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -10,7 +10,7 @@ async def test_get(server): response = await client.get(url) assert response.status_code == 200 assert response.text == "Hello, world!" - assert response.protocol == "HTTP/1.1" + assert response.http_version == "HTTP/1.1" assert response.headers assert repr(response) == "" diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 6ae4633a..293d2163 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -32,7 +32,7 @@ def test_get(server): assert response.url == httpx.URL(url) assert response.content == b"Hello, world!" assert response.text == "Hello, world!" - assert response.protocol == "HTTP/1.1" + assert response.http_version == "HTTP/1.1" assert response.encoding == "iso-8859-1" assert response.request.url == httpx.URL(url) assert response.headers