Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: encode/httpcore
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.17.2
Choose a base ref
...
head repository: encode/httpcore
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.17.3
Choose a head ref
  • 16 commits
  • 44 files changed
  • 5 contributors

Commits on May 26, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    444e042 View commit details

Commits on Jun 5, 2023

  1. Bump black from 23.1.0 to 23.3.0 (#705)

    Bumps [black](https://github.com/psf/black) from 23.1.0 to 23.3.0.
    - [Release notes](https://github.com/psf/black/releases)
    - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
    - [Commits](psf/black@23.1.0...23.3.0)
    
    ---
    updated-dependencies:
    - dependency-name: black
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d3e18e3 View commit details
  2. Bump pytest from 7.2.0 to 7.3.1 (#707)

    Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.2.0 to 7.3.1.
    - [Release notes](https://github.com/pytest-dev/pytest/releases)
    - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
    - [Commits](pytest-dev/pytest@7.2.0...7.3.1)
    
    ---
    updated-dependencies:
    - dependency-name: pytest
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Zanie Adkins <michael@prefect.io>
    dependabot[bot] and zanieb authored Jun 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e597a94 View commit details

Commits on Jun 6, 2023

  1. Bump mkdocstrings[python-legacy] from 0.19.1 to 0.22.0 (#709)

    Bumps [mkdocstrings[python-legacy]](https://github.com/mkdocstrings/mkdocstrings) from 0.19.1 to 0.22.0.
    - [Release notes](https://github.com/mkdocstrings/mkdocstrings/releases)
    - [Changelog](https://github.com/mkdocstrings/mkdocstrings/blob/master/CHANGELOG.md)
    - [Commits](mkdocstrings/mkdocstrings@0.19.1...0.22.0)
    
    ---
    updated-dependencies:
    - dependency-name: mkdocstrings[python-legacy]
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 6, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9687ed0 View commit details

Commits on Jun 7, 2023

  1. Bump mkdocs-material from 9.1.5 to 9.1.15 (#706)

    Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.1.5 to 9.1.15.
    - [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
    - [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
    - [Commits](squidfunk/mkdocs-material@9.1.5...9.1.15)
    
    ---
    updated-dependencies:
    - dependency-name: mkdocs-material
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Tom Christie <tom@tomchristie.com>
    dependabot[bot] and tomchristie authored Jun 7, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bfd235f View commit details
  2. Documenting the network backend API (#699)

    * Documenting the network backend API
    
    * Add example for working with a network backend directly
    
    * Network backend docs
    
    * Update docs/network-backends.md
    
    Co-authored-by: Florimond Manca <florimond.manca@protonmail.com>
    
    * Add 'httpcore.AnyIONetworkBackend' and 'httpcore.TrioNetworkBackend' to the API
    
    * Add networking backends to top-level API
    
    * httpcore.backends becomes private, since backends are available at documented top-level API now
    
    * Justify TrioBackend over AnyIOBackend
    
    * Rename '_backends/asyncio.py' to '_backends/anyio.py'
    
    * Use neater join for HTTP/1.1 example
    
    * Tweak example of working with stream directly
    
    * Minor docs tweaks, from working through
    
    * Minor docs tweaks, from working through
    
    * Minor test tweak
    
    * Link to network backends docs from 'network_stream' extension docs
    
    * Add Networking Backend line item to the CHANGELOG
    
    ---------
    
    Co-authored-by: Florimond Manca <florimond.manca@protonmail.com>
    tomchristie and florimondmanca authored Jun 7, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1497a42 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1d90b36 View commit details

Commits on Jun 12, 2023

  1. Add exceptions for invalid trace callback (#717)

    * Add exceptions for invalid trace callback
    
    * Lint
    
    * Enforce coverage
    
    * Check if returned value is coroutine or not
    
    * Coverage
    
    * update changelog
    karpetrosyan authored Jun 12, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7548dd5 View commit details
  2. Docstrings and minor refactor for HTTP/2. (#720)

    * Add HTTP/2 data_stream extension
    
    * Expose HTTP2DataStream in 'data_stream' extension.
    
    * Remove data_stream extension
    
    * Remove unrelated change of 'network_stream' extension
    tomchristie authored Jun 12, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    eb5957d View commit details

Commits on Jun 16, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aacdbb9 View commit details

Commits on Jun 26, 2023

  1. Graceful handling for HTTP/2 GoAway frames. (#733)

    * Refactor HTTP/2 stream events
    
    * Refactor HTTP/2 stream events
    
    * Graceful handling of HTTP/2 GoAway frames
    
    * Add to CHANGELOG
    
    * Remove unneccessary getattr
    
    * Conditional fix
    
    * Conditional fix
    tomchristie authored Jun 26, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8d31f0b View commit details

Commits on Jul 3, 2023

  1. Bump pytest-httpbin from 2.0.0rc1 to 2.0.0 (#740)

    Bumps [pytest-httpbin](https://github.com/kevin1024/pytest-httpbin) from 2.0.0rc1 to 2.0.0.
    - [Release notes](https://github.com/kevin1024/pytest-httpbin/releases)
    - [Changelog](https://github.com/kevin1024/pytest-httpbin/blob/master/release.py)
    - [Commits](kevin1024/pytest-httpbin@v2.0.0rc1...v2.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: pytest-httpbin
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 3, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    00717b3 View commit details
  2. Bump pytest from 7.3.1 to 7.4.0 (#742)

    Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.3.1 to 7.4.0.
    - [Release notes](https://github.com/pytest-dev/pytest/releases)
    - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
    - [Commits](pytest-dev/pytest@7.3.1...7.4.0)
    
    ---
    updated-dependencies:
    - dependency-name: pytest
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 3, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2014bc8 View commit details
  3. Bump coverage from 6.5.0 to 7.2.7 (#743)

    Bumps [coverage](https://github.com/nedbat/coveragepy) from 6.5.0 to 7.2.7.
    - [Release notes](https://github.com/nedbat/coveragepy/releases)
    - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
    - [Commits](nedbat/coveragepy@6.5.0...7.2.7)
    
    ---
    updated-dependencies:
    - dependency-name: coverage
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Tom Christie <tom@tomchristie.com>
    dependabot[bot] and tomchristie authored Jul 3, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    630e1e9 View commit details

Commits on Jul 4, 2023

  1. Support async cancellations. (#726)

    * Add 'AsyncShieldCancellation' context manager
    
    * Update _synchronization.py
    
    * Linting
    
    * Fix docstring wording
    
    * Add interim 'nocover' to show tests passing.
    
    * Add failing test case for HTTP/1.1 cancellations
    
    * Neat cleanup for HTTP/1.1 write cancellations
    
    * Drop 'nocover' for ShieldCancellation
    
    * Add failing test case for HTTP/1.1 cancellations during response reading
    
    * Resolve failing test case
    
    * Add failing test cases for cancellations on connection pools
    
    * Resolve failing test cases
    
    * Add failing test cases for cancellations on HTTP/2 connections
    
    * Resolve failing test cases
    
    * Add failing test cases for cancellations on HTTP/2 connections when reading response
    
    * Resolve failing test cases
    
    * Update CHANGELOG
    
    * Fix yield behaviour
    tomchristie authored Jul 4, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    31a4a56 View commit details
  2. Version 0.17.3 (#744)

    * Version 0.17.3
    
    * Remove release date
    
    * Sort changes by importance
    
    * Add release date
    
    ---------
    
    Co-authored-by: Tom Christie <tom@tomchristie.com>
    karpetrosyan and tomchristie authored Jul 4, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    327e8bd View commit details
Showing with 1,544 additions and 499 deletions.
  1. +7 −0 CHANGELOG.md
  2. +6 −0 docs/extensions.md
  3. +277 −1 docs/network-backends.md
  4. +49 −1 httpcore/__init__.py
  5. +2 −2 httpcore/_async/connection.py
  6. +7 −5 httpcore/_async/connection_pool.py
  7. +7 −5 httpcore/_async/http11.py
  8. +113 −38 httpcore/_async/http2.py
  9. +1 −1 httpcore/_async/http_proxy.py
  10. +2 −2 httpcore/_async/socks_proxy.py
  11. 0 httpcore/{backends → _backends}/__init__.py
  12. +5 −5 httpcore/{backends/asyncio.py → _backends/anyio.py}
  13. +2 −2 httpcore/{backends → _backends}/auto.py
  14. 0 httpcore/{backends → _backends}/base.py
  15. 0 httpcore/{backends → _backends}/mock.py
  16. 0 httpcore/{backends → _backends}/sync.py
  17. 0 httpcore/{backends → _backends}/trio.py
  18. +2 −2 httpcore/_sync/connection.py
  19. +7 −5 httpcore/_sync/connection_pool.py
  20. +7 −5 httpcore/_sync/http11.py
  21. +113 −38 httpcore/_sync/http2.py
  22. +1 −1 httpcore/_sync/http_proxy.py
  23. +2 −2 httpcore/_sync/socks_proxy.py
  24. +65 −0 httpcore/_synchronization.py
  25. +16 −2 httpcore/_trace.py
  26. +1 −0 mkdocs.yml
  27. +6 −6 requirements.txt
  28. +12 −7 tests/_async/test_connection.py
  29. +167 −55 tests/_async/test_connection_pool.py
  30. +41 −48 tests/_async/test_http11.py
  31. +44 −44 tests/_async/test_http2.py
  32. +13 −8 tests/_async/test_http_proxy.py
  33. +4 −4 tests/_async/test_integration.py
  34. +18 −19 tests/_async/test_socks_proxy.py
  35. +12 −7 tests/_sync/test_connection.py
  36. +167 −55 tests/_sync/test_connection_pool.py
  37. +41 −48 tests/_sync/test_http11.py
  38. +44 −44 tests/_sync/test_http2.py
  39. +13 −8 tests/_sync/test_http_proxy.py
  40. +4 −4 tests/_sync/test_integration.py
  41. +18 −19 tests/_sync/test_socks_proxy.py
  42. +242 −0 tests/test_cancellations.py
  43. +5 −5 tests/test_models.py
  44. +1 −1 unasync.py
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 0.17.3 (5th July 2023)

- Support async cancellations, ensuring that the connection pool is left in a clean state when cancellations occur. (#726)
- The networking backend interface has [been added to the public API](https://www.encode.io/httpcore/network-backends). Some classes which were previously private implementation detail are now part of the top-level public API. (#699)
- Graceful handling of HTTP/2 GoAway frames, with requests being transparently retried on a new connection. (#730)
- Add exceptions when a synchronous `trace callback` is passed to an asynchronous request or an asynchronous `trace callback` is passed to a synchronous request. (#717)

## 0.17.2 (May 23th, 2023)

- Add `socket_options` argument to `ConnectionPool` and `HTTProxy` classes. (#668)
6 changes: 6 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
@@ -182,6 +182,10 @@ HTTP/2 onwards does not include a reason phrase on the wire.

When no key is included, a default based on the status code may be used.

### `"stream_id"`

When HTTP/2 is being used the `"stream_id"` response extension can be accessed to determine the ID of the data stream that the response was sent on.

### `"network_stream"`

The `"network_stream"` extension allows developers to handle HTTP `CONNECT` and `Upgrade` requests, by providing an API that steps outside the standard request/response model, and can directly read or write to the network.
@@ -196,6 +200,8 @@ The interface provided by the network stream:

This API can be used as the foundation for working with HTTP proxies, WebSocket upgrades, and other advanced use-cases.

See the [network backends documentation](network-backends.md) for more information on working directly with network streams.

##### `CONNECT` requests

A proxy CONNECT request using the network stream:
278 changes: 277 additions & 1 deletion docs/network-backends.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,279 @@
# Network Backends

TODO
The API layer at which `httpcore` interacts with the network is described as the network backend. Various backend implementations are provided, allowing `httpcore` to handle networking in different runtime contexts.

## Working with network backends

### The default network backend

Typically you won't need to specify a network backend, as a default will automatically be selected. However, understanding how the network backends fit in may be useful if you want to better understand the underlying architecture. Let's start by seeing how we can explicitly select the network backend.

First we're making a standard HTTP request, using a connection pool:

```python
import httpcore

with httpcore.ConnectionPool() as http:
response = http.request('GET', 'https://www.example.com')
print(response)
```

We can also have the same behavior, but be explicit with our selection of the network backend:

```python
import httpcore

network_backend = httpcore.SyncBackend()
with httpcore.ConnectionPool(network_backend=network_backend) as http:
response = http.request('GET', 'https://www.example.com')
print(response)
```

The `httpcore.SyncBackend()` implementation handles the opening of TCP connections, and operations on the socket stream, such as reading, writing, and closing the connection.

We can get a better understanding of this by using a network backend to send a basic HTTP/1.1 request directly:

```python
import httpcore

# Create an SSL context using 'certifi' for the certificates.
ssl_context = httpcore.default_ssl_context()

# A basic HTTP/1.1 request as a plain bytestring.
request = b'\r\n'.join([
b'GET / HTTP/1.1',
b'Host: www.example.com',
b'Accept: */*',
b'Connection: close',
b''
])

# Open a TCP stream and upgrade it to SSL.
network_backend = httpcore.SyncBackend()
network_stream = network_backend.connect_tcp("www.example.com", 443)
network_stream = network_stream.start_tls(ssl_context, server_hostname="www.example.com")

# Send the HTTP request.
network_stream.write(request)

# Read the HTTP response.
while True:
response = network_stream.read(max_bytes=4096)
if response == b'':
break
print(response)

# The output should look something like this:
#
# b'HTTP/1.1 200 OK\r\nAge: 600005\r\n [...] Content-Length: 1256\r\nConnection: close\r\n\r\n'
# b'<!doctype html>\n<html>\n<head>\n <title>Example Domain</title> [...] </html>\n'
```

### Async network backends

If we're working with an `async` codebase, then we need to select a different backend.

The `httpcore.AnyIOBackend` is suitable for usage if you're running under `asyncio`. This is a networking backend implemented using [the `anyio` package](https://anyio.readthedocs.io/en/3.x/).

```python
import httpcore
import asyncio

async def main():
network_backend = httpcore.AnyIOBackend()
async with httpcore.AsyncConnectionPool(network_backend=network_backend) as http:
response = await http.request('GET', 'https://www.example.com')
print(response)

asyncio.run(main())
```

The `AnyIOBackend` will work when running under either `asyncio` or `trio`. However, if you're working with async using the [`trio` framework](https://trio.readthedocs.io/en/stable/), then we recommend using the `httpcore.TrioBackend`.

This will give you the same kind of networking behavior you'd have using `AnyIOBackend`, but there will be a little less indirection so it will be marginally more efficient and will present cleaner tracebacks in error cases.

```python
import httpcore
import trio

async def main():
network_backend = httpcore.TrioBackend()
async with httpcore.AsyncConnectionPool(network_backend=network_backend) as http:
response = await http.request('GET', 'https://www.example.com')
print(response)

trio.run(main)
```

### Mock network backends

There are also mock network backends available that can be useful for testing purposes.
These backends accept a list of bytes, and return network stream interfaces that return those byte streams.

Here's an example of mocking a simple HTTP/1.1 response...

```python
import httpcore

network_backend = httpcore.MockBackend([
b"HTTP/1.1 200 OK\r\n",
b"Content-Type: plain/text\r\n",
b"Content-Length: 13\r\n",
b"\r\n",
b"Hello, world!",
])
with httpcore.ConnectionPool(network_backend=network_backend) as http:
response = http.request("GET", "https://example.com/")
print(response.extensions['http_version'])
print(response.status)
print(response.content)
```

Mocking a HTTP/2 response is more complex, since it uses a binary format...

```python
import hpack
import hyperframe.frame
import httpcore

content = [
hyperframe.frame.SettingsFrame().serialize(),
hyperframe.frame.HeadersFrame(
stream_id=1,
data=hpack.Encoder().encode(
[
(b":status", b"200"),
(b"content-type", b"plain/text"),
]
),
flags=["END_HEADERS"],
).serialize(),
hyperframe.frame.DataFrame(
stream_id=1, data=b"Hello, world!", flags=["END_STREAM"]
).serialize(),
]
# Note that we instantiate the mock backend with an `http2=True` argument.
# This ensures that the mock network stream acts as if the `h2` ALPN flag has been set,
# and causes the connection pool to interact with the connection using HTTP/2.
network_backend = httpcore.MockBackend(content, http2=True)
with httpcore.ConnectionPool(network_backend=network_backend) as http:
response = http.request("GET", "https://example.com/")
print(response.extensions['http_version'])
print(response.status)
print(response.content)
```

### Custom network backends

The base interface for network backends is provided as public API, allowing you to implement custom networking behavior.

You can use this to provide advanced networking functionality such as:

* Network recording / replay.
* In-depth debug tooling.
* Handling non-standard SSL or DNS requirements.

Here's an example that records the network response to a file on disk:

```python
import httpcore


class RecordingNetworkStream(httpcore.NetworkStream):
def __init__(self, record_file, stream):
self.record_file = record_file
self.stream = stream

def read(self, max_bytes, timeout=None):
data = self.stream.read(max_bytes, timeout=timeout)
self.record_file.write(data)
return data

def write(self, buffer, timeout=None):
self.stream.write(buffer, timeout=timeout)

def close(self) -> None:
self.stream.close()

def start_tls(
self,
ssl_context,
server_hostname=None,
timeout=None,
):
self.stream = self.stream.start_tls(
ssl_context, server_hostname=server_hostname, timeout=timeout
)
return self

def get_extra_info(self, info):
return self.stream.get_extra_info(info)


class RecordingNetworkBackend(httpcore.NetworkBackend):
"""
A custom network backend that records network responses.
"""
def __init__(self, record_file):
self.record_file = record_file
self.backend = httpcore.SyncBackend()

def connect_tcp(
self,
host,
port,
timeout=None,
local_address=None,
socket_options=None,
):
# Note that we're only using a single record file here,
# so even if multiple connections are opened the network
# traffic will all write to the same file.

# An alternative implementation might automatically use
# a new file for each opened connection.
stream = self.backend.connect_tcp(
host,
port,
timeout=timeout,
local_address=local_address,
socket_options=socket_options
)
return RecordingNetworkStream(self.record_file, stream)


# Once you make the request, the raw HTTP/1.1 response will be available
# in the 'network-recording' file.
#
# Try switching to `http2=True` to see the difference when recording HTTP/2 binary network traffic,
# or add `headers={'Accept-Encoding': 'gzip'}` to see HTTP content compression.
with open("network-recording", "wb") as record_file:
network_backend = RecordingNetworkBackend(record_file)
with httpcore.ConnectionPool(network_backend=network_backend) as http:
response = http.request("GET", "https://www.example.com/")
print(response)
```

---

## Reference

### Networking Backends

* `httpcore.SyncBackend`
* `httpcore.AnyIOBackend`
* `httpcore.TrioBackend`

### Mock Backends

* `httpcore.MockBackend`
* `httpcore.MockStream`
* `httpcore.AsyncMockBackend`
* `httpcore.AsyncMockStream`

### Base Interface

* `httpcore.NetworkBackend`
* `httpcore.NetworkStream`
* `httpcore.AsyncNetworkBackend`
* `httpcore.AsyncNetworkStream`
50 changes: 49 additions & 1 deletion httpcore/__init__.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,15 @@
AsyncHTTPProxy,
AsyncSOCKSProxy,
)
from ._backends.base import (
SOCKET_OPTION,
AsyncNetworkBackend,
AsyncNetworkStream,
NetworkBackend,
NetworkStream,
)
from ._backends.mock import AsyncMockBackend, AsyncMockStream, MockBackend, MockStream
from ._backends.sync import SyncBackend
from ._exceptions import (
ConnectError,
ConnectionNotAvailable,
@@ -37,6 +46,30 @@
SOCKSProxy,
)

# The 'httpcore.AnyIOBackend' class is conditional on 'anyio' being installed.
try:
from ._backends.anyio import AnyIOBackend
except ImportError: # pragma: nocover

class AnyIOBackend: # type: ignore
def __init__(self, *args, **kwargs): # type: ignore
msg = (
"Attempted to use 'httpcore.AnyIOBackend' but 'anyio' is not installed."
)
raise RuntimeError(msg)


# The 'httpcore.TrioBackend' class is conditional on 'trio' being installed.
try:
from ._backends.trio import TrioBackend
except ImportError: # pragma: nocover

class TrioBackend: # type: ignore
def __init__(self, *args, **kwargs): # type: ignore
msg = "Attempted to use 'httpcore.TrioBackend' but 'trio' is not installed."
raise RuntimeError(msg)


__all__ = [
# top-level requests
"request",
@@ -62,8 +95,23 @@
"HTTP2Connection",
"ConnectionInterface",
"SOCKSProxy",
# network backends, implementations
"SyncBackend",
"AnyIOBackend",
"TrioBackend",
# network backends, mock implementations
"AsyncMockBackend",
"AsyncMockStream",
"MockBackend",
"MockStream",
# network backends, interface
"AsyncNetworkStream",
"AsyncNetworkBackend",
"NetworkStream",
"NetworkBackend",
# util
"default_ssl_context",
"SOCKET_OPTION",
# exceptions
"ConnectionNotAvailable",
"ProxyError",
@@ -82,7 +130,7 @@
"WriteError",
]

__version__ = "0.17.2"
__version__ = "0.17.3"


__locals = locals()
Loading