Skip to content

Commit f9b9391

Browse files
httpcore 0.14 redesign (#420)
* httpcore 0.14 redesign * Add types-certifi to requirements * Run unasync * Make tests more liberal when inspecting 'stream.get_extra_info(socket)' * Make tests more liberal when inspecting 'stream.get_extra_info(socket)' * Drop unused import * Update test matrix from '3.10.0-beta.4' to '3.10' * Update docs * Update requirements * Update README, docs * Update CHANGELOG * py.typed * Minor docs tweak * Update CHANGELOG
1 parent 85a1f9e commit f9b9391

103 files changed

Lines changed: 7793 additions & 8555 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10.0-beta.4"]
17+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
1818

1919
steps:
2020
- uses: "actions/checkout@v2"

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
44

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

7+
## 0.14.0
8+
9+
The 0.14 release is a complete reworking of `httpcore`, comprehensively addressing some underlying issues in the connection pooling, as well as substantially redesigning the API to be more user friendly.
10+
11+
Some of the lower-level API design also makes the components more easily testable in isolation, and the package now has 100% test coverage.
12+
13+
See [discussion #419](https://github.com/encode/httpcore/discussions/419) for a little more background.
14+
15+
There's some other neat bits in there too, such as the "trace" extension, which gives a hook into inspecting the internal events that occur during the request/response cycle. This extension is needed for the HTTPX cli, in order to...
16+
17+
* Log the point at which the connection is established, and the IP/port on which it is made.
18+
* Determine if the outgoing request should log as HTTP/1.1 or HTTP/2, rather than having to assume it's HTTP/2 if the --http2 flag was passed. (Which may not actually be true.)
19+
* Log SSL version info / certificate info.
20+
21+
Note that `curio` support is not currently available in 0.14.0. If you're using `httpcore` with `curio` please get in touch, so we can assess if we ought to prioritize it as a feature or not.
22+
723
## 0.13.7 (September 13th, 2021)
824

925
- Fix broken error messaging when URL scheme is missing, or a non HTTP(S) scheme is used. (Pull #403)

README.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,59 @@ defaults, or any of that Jazz.
1717
Some things HTTP Core does do:
1818

1919
* Sending HTTP requests.
20-
* Provides both sync and async interfaces.
21-
* Supports HTTP/1.1 and HTTP/2.
22-
* Async backend support for `asyncio`, `trio` and `curio`.
23-
* Automatic connection pooling.
20+
* Thread-safe / task-safe connection pooling.
2421
* HTTP(S) proxy support.
22+
* Supports HTTP/1.1 and HTTP/2.
23+
* Provides both sync and async interfaces.
24+
* Async backend support for `asyncio` and `trio`.
2525

2626
## Installation
2727

2828
For HTTP/1.1 only support, install with...
2929

3030
```shell
31-
$ pip install httpcore
31+
$ pip install git+https://github.com/encode/httpcore
3232
```
3333

3434
For HTTP/1.1 and HTTP/2 support, install with...
3535

3636
```shell
37-
$ pip install httpcore[http2]
37+
$ pip install git+https://github.com/encode/httpcore[http2]
3838
```
3939

40-
## Quickstart
40+
# Sending requests
4141

42-
Here's an example of making an HTTP GET request using `httpcore`...
42+
Send an HTTP request:
4343

4444
```python
45-
with httpcore.SyncConnectionPool() as http:
46-
status_code, headers, stream, extensions = http.handle_request(
47-
method=b'GET',
48-
url=(b'https', b'example.org', 443, b'/'),
49-
headers=[(b'host', b'example.org'), (b'user-agent', b'httpcore')],
50-
stream=httpcore.ByteStream(b''),
51-
extensions={}
52-
)
53-
body = stream.read()
54-
print(status_code, body)
45+
import httpcore
46+
47+
response = httpcore.request("GET", "https://www.example.com/")
48+
49+
print(response)
50+
# <Response [200]>
51+
print(response.status)
52+
# 200
53+
print(response.headers)
54+
# [(b'Accept-Ranges', b'bytes'), (b'Age', b'557328'), (b'Cache-Control', b'max-age=604800'), ...]
55+
print(response.content)
56+
# b'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n\n<meta charset="utf-8"/>\n ...'
5557
```
5658

57-
Or, using async...
59+
The top-level `httpcore.request()` function is provided for convenience. In practice whenever you're working with `httpcore` you'll want to use the connection pooling functionality that it provides.
5860

5961
```python
60-
async with httpcore.AsyncConnectionPool() as http:
61-
status_code, headers, stream, extensions = await http.handle_async_request(
62-
method=b'GET',
63-
url=(b'https', b'example.org', 443, b'/'),
64-
headers=[(b'host', b'example.org'), (b'user-agent', b'httpcore')],
65-
stream=httpcore.ByteStream(b''),
66-
extensions={}
67-
)
68-
body = await stream.aread()
69-
print(status_code, body)
62+
import httpcore
63+
64+
pool = httpcore.ConnectionPool()
65+
response = pool.request("GET", "https://www.example.com/")
7066
```
7167

68+
Once you're ready to get going, [head over to the documentation](https://www.encode.io/httpcore/).
69+
7270
## Motivation
7371

74-
You probably don't want to be using HTTP Core directly. It might make sense if
72+
You *probably* don't want to be using HTTP Core directly. It might make sense if
7573
you're writing something like a proxy service in Python, and you just want
7674
something at the lowest possible level, but more typically you'll want to use
7775
a higher level client library, such as `httpx`.

docs/api.md

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)