Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop UDS support #726

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions httpx/backends/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 0 additions & 9 deletions httpx/backends/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
9 changes: 0 additions & 9 deletions httpx/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 0 additions & 18 deletions httpx/backends/trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions httpx/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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)
Expand All @@ -137,7 +135,6 @@ def __init__(
pool_limits=pool_limits,
backend=backend,
trust_env=trust_env,
uds=uds,
)

if base_url is None:
Expand Down
20 changes: 4 additions & 16 deletions httpx/dispatch/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}")
Expand Down
3 changes: 0 additions & 3 deletions httpx/dispatch/connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions tests/client/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 0 additions & 25 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
27 changes: 0 additions & 27 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down