From fffe464971cf9bbae8a8e97675bbbc8d42c2d0ad Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 6 Jan 2020 11:26:12 +0000 Subject: [PATCH] Drop UDS support --- httpx/backends/asyncio.py | 21 --------------------- httpx/backends/auto.py | 9 --------- httpx/backends/base.py | 9 --------- httpx/backends/trio.py | 18 ------------------ httpx/client.py | 3 --- httpx/dispatch/connection.py | 20 ++++---------------- httpx/dispatch/connection_pool.py | 3 --- tests/client/test_async_client.py | 12 ------------ tests/client/test_client.py | 12 ------------ tests/conftest.py | 25 ------------------------- tests/test_concurrency.py | 27 --------------------------- 11 files changed, 4 insertions(+), 155 deletions(-) diff --git a/httpx/backends/asyncio.py b/httpx/backends/asyncio.py index 74d2b0d4f8..7942558e4e 100644 --- a/httpx/backends/asyncio.py +++ b/httpx/backends/asyncio.py @@ -198,27 +198,6 @@ async def open_tcp_stream( return SocketStream(stream_reader=stream_reader, stream_writer=stream_writer) - async def open_uds_stream( - self, - path: str, - hostname: typing.Optional[str], - ssl_context: typing.Optional[ssl.SSLContext], - timeout: Timeout, - ) -> SocketStream: - server_hostname = hostname if ssl_context else None - - try: - stream_reader, stream_writer = await asyncio.wait_for( # type: ignore - asyncio.open_unix_connection( - path, ssl=ssl_context, server_hostname=server_hostname - ), - timeout.connect_timeout, - ) - except asyncio.TimeoutError: - raise ConnectTimeout() - - return SocketStream(stream_reader=stream_reader, stream_writer=stream_writer) - def time(self) -> float: loop = asyncio.get_event_loop() return loop.time() diff --git a/httpx/backends/auto.py b/httpx/backends/auto.py index 7a8c597822..ff18712512 100644 --- a/httpx/backends/auto.py +++ b/httpx/backends/auto.py @@ -32,15 +32,6 @@ async def open_tcp_stream( ) -> BaseSocketStream: return await self.backend.open_tcp_stream(hostname, port, ssl_context, timeout) - async def open_uds_stream( - self, - path: str, - hostname: typing.Optional[str], - ssl_context: typing.Optional[ssl.SSLContext], - timeout: Timeout, - ) -> BaseSocketStream: - return await self.backend.open_uds_stream(path, hostname, ssl_context, timeout) - def time(self) -> float: return self.backend.time() diff --git a/httpx/backends/base.py b/httpx/backends/base.py index 964d09449f..683d8edb3d 100644 --- a/httpx/backends/base.py +++ b/httpx/backends/base.py @@ -102,15 +102,6 @@ async def open_tcp_stream( ) -> BaseSocketStream: raise NotImplementedError() # pragma: no cover - async def open_uds_stream( - self, - path: str, - hostname: typing.Optional[str], - ssl_context: typing.Optional[ssl.SSLContext], - timeout: Timeout, - ) -> BaseSocketStream: - raise NotImplementedError() # pragma: no cover - def time(self) -> float: raise NotImplementedError() # pragma: no cover diff --git a/httpx/backends/trio.py b/httpx/backends/trio.py index 979aa450b7..17e3dffc1f 100644 --- a/httpx/backends/trio.py +++ b/httpx/backends/trio.py @@ -101,24 +101,6 @@ async def open_tcp_stream( raise ConnectTimeout() - async def open_uds_stream( - self, - path: str, - hostname: typing.Optional[str], - ssl_context: typing.Optional[ssl.SSLContext], - timeout: Timeout, - ) -> SocketStream: - connect_timeout = none_as_inf(timeout.connect_timeout) - - with trio.move_on_after(connect_timeout): - stream: trio.SocketStream = await trio.open_unix_socket(path) - if ssl_context is not None: - stream = trio.SSLStream(stream, ssl_context, server_hostname=hostname) - await stream.do_handshake() - return SocketStream(stream=stream) - - raise ConnectTimeout() - def time(self) -> float: return trio.current_time() diff --git a/httpx/client.py b/httpx/client.py index 75f29ac3b7..e34bacdc00 100644 --- a/httpx/client.py +++ b/httpx/client.py @@ -102,7 +102,6 @@ class AsyncClient: instance. Defaults to 'auto', for autodetection. * **trust_env** - *(optional)* Enables or disables usage of environment variables for configuration. - * **uds** - *(optional)* A path to a Unix domain socket to connect through. """ def __init__( @@ -124,7 +123,6 @@ def __init__( app: typing.Callable = None, backend: typing.Union[str, ConcurrencyBackend] = "auto", trust_env: bool = True, - uds: str = None, ): if app is not None: dispatch = ASGIDispatch(app=app) @@ -137,7 +135,6 @@ def __init__( pool_limits=pool_limits, backend=backend, trust_env=trust_env, - uds=uds, ) if base_url is None: diff --git a/httpx/dispatch/connection.py b/httpx/dispatch/connection.py index d9e104b0c8..8df6183379 100644 --- a/httpx/dispatch/connection.py +++ b/httpx/dispatch/connection.py @@ -25,13 +25,11 @@ def __init__( ssl: SSLConfig = None, backend: typing.Union[str, ConcurrencyBackend] = "auto", release_func: typing.Optional[ReleaseCallback] = None, - uds: typing.Optional[str] = None, ): self.origin = Origin(origin) if isinstance(origin, str) else origin self.ssl = SSLConfig() if ssl is None else ssl self.backend = lookup_backend(backend) self.release_func = release_func - self.uds = uds self.connection: typing.Union[None, HTTP11Connection, HTTP2Connection] = None self.expires_at: typing.Optional[float] = None @@ -55,20 +53,10 @@ async def connect( else: on_release = functools.partial(self.release_func, self) - if self.uds is None: - logger.trace( - f"start_connect tcp host={host!r} port={port!r} timeout={timeout!r}" - ) - socket = await self.backend.open_tcp_stream( - host, port, ssl_context, timeout - ) - else: - logger.trace( - f"start_connect uds path={self.uds!r} host={host!r} timeout={timeout!r}" - ) - socket = await self.backend.open_uds_stream( - self.uds, host, ssl_context, timeout - ) + logger.trace( + f"start_connect tcp host={host!r} port={port!r} timeout={timeout!r}" + ) + socket = await self.backend.open_tcp_stream(host, port, ssl_context, timeout) http_version = socket.get_http_version() logger.trace(f"connected http_version={http_version!r}") diff --git a/httpx/dispatch/connection_pool.py b/httpx/dispatch/connection_pool.py index 3e09b11017..12e190694c 100644 --- a/httpx/dispatch/connection_pool.py +++ b/httpx/dispatch/connection_pool.py @@ -97,12 +97,10 @@ def __init__( pool_limits: PoolLimits = DEFAULT_POOL_LIMITS, http2: bool = False, backend: typing.Union[str, ConcurrencyBackend] = "auto", - uds: typing.Optional[str] = None, ): self.ssl = SSLConfig(verify=verify, cert=cert, trust_env=trust_env, http2=http2) self.pool_limits = pool_limits self.is_closed = False - self.uds = uds self.keepalive_connections = ConnectionStore() self.active_connections = ConnectionStore() @@ -173,7 +171,6 @@ async def acquire_connection( ssl=self.ssl, backend=self.backend, release_func=self.release_connection, - uds=self.uds, ) logger.trace(f"new_connection connection={connection!r}") else: diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 5943839966..539caa47b1 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -150,18 +150,6 @@ async def test_100_continue(server): assert response.content == data -@pytest.mark.usefixtures("async_environment") -async def test_uds(uds_server): - url = uds_server.url - uds = uds_server.config.uds - assert uds is not None - async with httpx.AsyncClient(uds=uds) as client: - response = await client.get(url) - assert response.status_code == 200 - assert response.text == "Hello, world!" - assert response.encoding == "iso-8859-1" - - async def test_explicit_backend(server, async_environment): async with httpx.AsyncClient(backend=async_environment) as client: response = await client.get(server.url) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 7c87722404..0628318827 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -154,18 +154,6 @@ async def test_base_url(server): assert response.url == base_url -@pytest.mark.asyncio -async def test_uds(uds_server): - url = uds_server.url - uds = uds_server.config.uds - assert uds is not None - async with httpx.AsyncClient(uds=uds) as client: - response = await client.get(url) - assert response.status_code == 200 - assert response.text == "Hello, world!" - assert response.encoding == "iso-8859-1" - - def test_merge_url(): client = httpx.AsyncClient(base_url="https://www.paypal.com/") url = client.merge_url("http://www.paypal.com") diff --git a/tests/conftest.py b/tests/conftest.py index 3edb46681e..15ae78bbfc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -295,15 +295,6 @@ def server(): yield from serve_in_thread(server) -@pytest.fixture(scope=SERVER_SCOPE) -def uds_server(): - uds = "test_server.sock" - config = Config(app=app, lifespan="off", loop="asyncio", uds=uds) - server = TestServer(config=config) - yield from serve_in_thread(server) - os.remove(uds) - - @pytest.fixture(scope=SERVER_SCOPE) def https_server(cert_pem_file, cert_private_key_file): config = Config( @@ -317,19 +308,3 @@ def https_server(cert_pem_file, cert_private_key_file): ) server = TestServer(config=config) yield from serve_in_thread(server) - - -@pytest.fixture(scope=SERVER_SCOPE) -def https_uds_server(cert_pem_file, cert_private_key_file): - uds = "https_test_server.sock" - config = Config( - app=app, - lifespan="off", - ssl_certfile=cert_pem_file, - ssl_keyfile=cert_private_key_file, - uds=uds, - loop="asyncio", - ) - server = TestServer(config=config) - yield from serve_in_thread(server) - os.remove(uds) diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 3ed755209a..6954017c03 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -56,33 +56,6 @@ async def test_start_tls_on_tcp_socket_stream(https_server): await stream.close() -@pytest.mark.usefixtures("async_environment") -async def test_start_tls_on_uds_socket_stream(https_uds_server): - backend = lookup_backend() - ctx = SSLConfig().load_ssl_context_no_verify() - timeout = Timeout(5) - - stream = await backend.open_uds_stream( - https_uds_server.config.uds, https_uds_server.url.host, None, timeout - ) - - try: - assert stream.is_connection_dropped() is False - assert get_cipher(stream) is None - - stream = await stream.start_tls(https_uds_server.url.host, ctx, timeout) - assert stream.is_connection_dropped() is False - assert get_cipher(stream) is not None - - await stream.write(b"GET / HTTP/1.1\r\n\r\n", timeout) - - response = await read_response(stream, timeout, should_contain=b"Hello, world") - assert response.startswith(b"HTTP/1.1 200 OK\r\n") - - finally: - await stream.close() - - @pytest.mark.usefixtures("async_environment") async def test_concurrent_read(server): """