Skip to content
Myr

Use public API only from transports (#1096)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 16893e4 · Browse files · 2 files+28 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

2 files+28 added−9 removed

  • other:+28 added−9 removed

2 files+28 added−9 removed

modified:httpx/_transports/asgi.py+22 added-5 removed
1from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union1from typing import (2 TYPE_CHECKING,3 AsyncIterator,4 Callable,5 Dict,6 List,7 Optional,8 Tuple,9 Union,10)1112import httpcore13import sniffio146from .._content_streams import ByteStream715if TYPE_CHECKING: # pragma: no cover16 import asyncio1718 import trio
11 unmodified lines
3031 return asyncio.Event()323334async def async_byte_iterator(bytestring: bytes) -> AsyncIterator[bytes]:35 yield bytestring363738class ASGITransport(httpcore.AsyncHTTPTransport):39 """40 A custom AsyncTransport that handles sending requests directly to an ASGI app.41 The simplest way to use this functionality is to use the `app` argument.
46 unmodified lines
88 stream: httpcore.AsyncByteStream = None,89 timeout: Dict[str, Optional[float]] = None,90 ) -> Tuple[bytes, int, bytes, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream]:91 headers = [] if headers is None else headers81 stream = ByteStream(b"") if stream is None else stream92 stream = (93 httpcore.AsyncByteStream(async_byte_iterator(b""))94 if stream is None95 else stream96 )9798 # ASGI scope.99 scheme, host, port, full_path = url100 path, _, query = full_path.partition(b"?")
68 unmodified lines
169 assert response_complete.is_set()170 assert status_code is not None171 assert response_headers is not None172158 stream = ByteStream(b"".join(body_parts))173 response_body = b"".join(body_parts)174175 stream = httpcore.AsyncByteStream(async_byte_iterator(response_body))176177 return (b"HTTP/1.1", status_code, b"", response_headers, stream)
modified:httpx/_transports/wsgi.py+6 added-4 removed
2 unmodified lines
3import typing45import httpcore67from .._content_streams import ByteStream, IteratorStream798def _skip_leading_empty_chunks(body: typing.Iterable) -> typing.Iterable:9 body = iter(body)10 for chunk in body:11 if chunk:
60 unmodified lines
72 typing.List[typing.Tuple[bytes, bytes]],73 httpcore.SyncByteStream,74 ]:75 headers = [] if headers is None else headers78 stream = ByteStream(b"") if stream is None else stream76 stream = (77 httpcore.SyncByteStream(chunk for chunk in [b""])78 if stream is None79 else stream80 )8182 scheme, host, port, full_path = url83 path, _, query = full_path.partition(b"?")84 environ = {
44 unmodified lines
129 headers = [130 (key.encode("ascii"), value.encode("ascii"))131 for key, value in seen_response_headers132 ]131 stream = IteratorStream(chunk for chunk in result)133 stream = httpcore.SyncByteStream(chunk for chunk in result)134135 return (b"HTTP/1.1", status_code, b"", headers, stream)