httpperf 1.0rc1__tar.gz → 1.0rc3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {httpperf-1.0rc1 → httpperf-1.0rc3}/NOTICE +54 -0
- {httpperf-1.0rc1/httpperf.egg-info → httpperf-1.0rc3}/PKG-INFO +14 -8
- {httpperf-1.0rc1 → httpperf-1.0rc3}/README.md +13 -7
- {httpperf-1.0rc1 → httpperf-1.0rc3}/httpperf/__init__.py +68 -12
- httpperf-1.0rc3/httpperf/version.py +1 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3/httpperf.egg-info}/PKG-INFO +14 -8
- {httpperf-1.0rc1 → httpperf-1.0rc3}/httpperf.egg-info/SOURCES.txt +3 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/httpperf.c +273 -62
- httpperf-1.0rc3/tests/test_api.py +542 -0
- httpperf-1.0rc3/tests/test_cancel.py +138 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_engine.py +45 -3
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_http_versions.py +75 -1
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_httpbin.py +5 -4
- httpperf-1.0rc3/tests/test_limiter.py +187 -0
- httpperf-1.0rc1/httpperf/version.py +0 -1
- {httpperf-1.0rc1 → httpperf-1.0rc3}/LICENSE +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/MANIFEST.in +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/httpperf.egg-info/dependency_links.txt +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/httpperf.egg-info/top_level.txt +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/pyproject.toml +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/setup.cfg +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/setup.py +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/.clang-format +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae.h +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae_epoll.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae_evport.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae_kqueue.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/ae_select.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/atomicvar.h +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/config.h +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/zmalloc.c +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/src/ae/zmalloc.h +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_connections.py +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_cookie.py +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_leaks.py +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_response.py +0 -0
- {httpperf-1.0rc1 → httpperf-1.0rc3}/tests/test_tls.py +0 -0
|
@@ -105,6 +105,60 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
105
105
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
106
106
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
107
107
|
|
|
108
|
+
=========================================================================
|
|
109
|
+
== nghttp3 Notice (bundled in binary wheels) ==
|
|
110
|
+
=========================================================================
|
|
111
|
+
|
|
112
|
+
The MIT License
|
|
113
|
+
|
|
114
|
+
Copyright (c) 2019 nghttp3 contributors
|
|
115
|
+
|
|
116
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
117
|
+
a copy of this software and associated documentation files (the
|
|
118
|
+
"Software"), to deal in the Software without restriction, including
|
|
119
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
120
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
121
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
122
|
+
the following conditions:
|
|
123
|
+
|
|
124
|
+
The above copyright notice and this permission notice shall be
|
|
125
|
+
included in all copies or substantial portions of the Software.
|
|
126
|
+
|
|
127
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
128
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
129
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
130
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
131
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
132
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
133
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
134
|
+
|
|
135
|
+
=========================================================================
|
|
136
|
+
== ngtcp2 Notice (bundled in binary wheels) ==
|
|
137
|
+
=========================================================================
|
|
138
|
+
|
|
139
|
+
The MIT License
|
|
140
|
+
|
|
141
|
+
Copyright (c) 2016 ngtcp2 contributors
|
|
142
|
+
|
|
143
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
144
|
+
a copy of this software and associated documentation files (the
|
|
145
|
+
"Software"), to deal in the Software without restriction, including
|
|
146
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
147
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
148
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
149
|
+
the following conditions:
|
|
150
|
+
|
|
151
|
+
The above copyright notice and this permission notice shall be
|
|
152
|
+
included in all copies or substantial portions of the Software.
|
|
153
|
+
|
|
154
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
155
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
156
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
157
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
158
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
159
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
160
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
161
|
+
|
|
108
162
|
=========================================================================
|
|
109
163
|
== OpenSSL Notice (bundled in binary wheels) ==
|
|
110
164
|
=========================================================================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpperf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.0rc3
|
|
4
4
|
Summary: An asyncio HTTP client for load testing, built on libcurl.
|
|
5
5
|
Author-email: Tony Simpson <agjasimpson@gmail.com>
|
|
6
6
|
Project-URL: Source, https://github.com/tonysimpson/httpperf
|
|
@@ -28,8 +28,6 @@ Dynamic: license-file
|
|
|
28
28
|
|
|
29
29
|
An asyncio HTTP client for load testing, built on libcurl.
|
|
30
30
|
|
|
31
|
-
httpperf was called acurl until version 1.0.
|
|
32
|
-
|
|
33
31
|
## Design
|
|
34
32
|
|
|
35
33
|
A load-testing client has three jobs: drive as much load as possible from each machine, report the server's response times rather than time spent waiting on the client, and read responses promptly so the server never sees a slow reader. httpperf is built around these.
|
|
@@ -52,15 +50,23 @@ Bytes are read off the wire as they arrive, whatever Python is doing. If Python
|
|
|
52
50
|
pip install httpperf
|
|
53
51
|
```
|
|
54
52
|
|
|
55
|
-
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2
|
|
53
|
+
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2 and HTTP/3.
|
|
56
54
|
|
|
57
|
-
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available.
|
|
55
|
+
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available: `curl -V` lists `HTTP3` under Features when it does.
|
|
58
56
|
|
|
59
57
|
```sh
|
|
60
58
|
sudo apt install libcurl4-openssl-dev # Debian/Ubuntu
|
|
61
59
|
pip install httpperf
|
|
62
60
|
```
|
|
63
61
|
|
|
62
|
+
To build against your own libcurl even where a wheel exists, skip the wheel, point the build at it and make sure it is found at run time:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
CFLAGS=-I$PREFIX/include LDFLAGS="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib" pip install --no-binary httpperf httpperf
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A session with `http_version="HTTP/3"` raises `ValueError` if the libcurl in use lacks HTTP/3.
|
|
69
|
+
|
|
64
70
|
## Quick start
|
|
65
71
|
|
|
66
72
|
```python
|
|
@@ -97,7 +103,7 @@ All arguments are keyword-only. A session can be created anywhere, even outside
|
|
|
97
103
|
| `max_host_connections` | `0` | Per-session cap on connections per host. Needs `connections="session"` or `"none"`. |
|
|
98
104
|
| `max_connections` | `0` | Per-session cap on connections in use. Needs `connections="session"` or `"none"`. |
|
|
99
105
|
| `cert` | `None` | `(certfile, keyfile)` paths for a client certificate, used by every request unless the request overrides it. |
|
|
100
|
-
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. |
|
|
106
|
+
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. Cancelling the task (or `asyncio.wait_for`) also stops the transfer and frees its connection slot; on HTTP/1.1 that closes the connection, on HTTP/2 and HTTP/3 it resets only that stream. |
|
|
101
107
|
| `connect_timeout` | `None` | Seconds allowed to connect, TLS included. `None` means curl's default of 300 s. |
|
|
102
108
|
| `verify` | `False` | Server certificate checking. `False`: none, as most load tests want. `True`: check against the system CA bundle: `SSL_CERT_FILE` if set, otherwise libcurl's own default, or the usual system locations if it has none. A path: check against that CA bundle. Requests can override it. |
|
|
103
109
|
| `json_dumps` | `None` | Function that turns a `json=` argument into the request body (`str` or `bytes`). `None` means the engine's. |
|
|
@@ -143,7 +149,7 @@ An engine binds to the asyncio loop running when it is first used, and so does a
|
|
|
143
149
|
| `cookies` | Dict of cookies to send with this request (added to the session jar). |
|
|
144
150
|
| `cookie_list` | List of `Cookie` objects. |
|
|
145
151
|
| `auth` | `(username, password)` for basic auth. |
|
|
146
|
-
| `data` | Request body: `str` or `bytes` as is, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
152
|
+
| `data` | Request body: `str` or `bytes` as is, with no `Content-Type` unless you set one, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
147
153
|
| `json` | Object to send as JSON, encoded with the session's `json_dumps`. Sets `Content-Type: application/json` unless you set it. |
|
|
148
154
|
| `files` | Dict (or list of pairs) of files to send as `multipart/form-data`, with any `data` dict as extra fields. A value is an open file, or `(filename, content)` or `(filename, content, content_type)`, where content is `bytes`, `str` or a file. Files are read into memory. |
|
|
149
155
|
| `cert` | `(certfile, keyfile)`, overriding the session's certificate. |
|
|
@@ -172,7 +178,7 @@ Failed transfers raise `httpperf.RequestError` with curl's detailed error messag
|
|
|
172
178
|
| `text` | Body decoded with `encoding`. |
|
|
173
179
|
| `encoding` | From the `Content-Type` charset, else latin-1 (`utf-8` for JSON). Can be set. |
|
|
174
180
|
| `json()` | Body parsed with the session's `json_loads`, once. By default the standard library, always as UTF-8, as RFC 8259 requires. |
|
|
175
|
-
| `cookies`, `cookielist` | The
|
|
181
|
+
| `cookies`, `cookielist` | The cookies this response set, from its `Set-Cookie` headers, as a dict or as `Cookie` objects. The session's whole jar is `session.cookies()`. |
|
|
176
182
|
| `primary_ip` | Address connected to. |
|
|
177
183
|
| `upload_size`, `download_size` | Bytes, as integers. |
|
|
178
184
|
| `request` | The `Request`: `method`, `url`, `headers`, `cookies`, `auth`, `data`. |
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
An asyncio HTTP client for load testing, built on libcurl.
|
|
4
4
|
|
|
5
|
-
httpperf was called acurl until version 1.0.
|
|
6
|
-
|
|
7
5
|
## Design
|
|
8
6
|
|
|
9
7
|
A load-testing client has three jobs: drive as much load as possible from each machine, report the server's response times rather than time spent waiting on the client, and read responses promptly so the server never sees a slow reader. httpperf is built around these.
|
|
@@ -26,15 +24,23 @@ Bytes are read off the wire as they arrive, whatever Python is doing. If Python
|
|
|
26
24
|
pip install httpperf
|
|
27
25
|
```
|
|
28
26
|
|
|
29
|
-
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2
|
|
27
|
+
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2 and HTTP/3.
|
|
30
28
|
|
|
31
|
-
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available.
|
|
29
|
+
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available: `curl -V` lists `HTTP3` under Features when it does.
|
|
32
30
|
|
|
33
31
|
```sh
|
|
34
32
|
sudo apt install libcurl4-openssl-dev # Debian/Ubuntu
|
|
35
33
|
pip install httpperf
|
|
36
34
|
```
|
|
37
35
|
|
|
36
|
+
To build against your own libcurl even where a wheel exists, skip the wheel, point the build at it and make sure it is found at run time:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
CFLAGS=-I$PREFIX/include LDFLAGS="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib" pip install --no-binary httpperf httpperf
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
A session with `http_version="HTTP/3"` raises `ValueError` if the libcurl in use lacks HTTP/3.
|
|
43
|
+
|
|
38
44
|
## Quick start
|
|
39
45
|
|
|
40
46
|
```python
|
|
@@ -71,7 +77,7 @@ All arguments are keyword-only. A session can be created anywhere, even outside
|
|
|
71
77
|
| `max_host_connections` | `0` | Per-session cap on connections per host. Needs `connections="session"` or `"none"`. |
|
|
72
78
|
| `max_connections` | `0` | Per-session cap on connections in use. Needs `connections="session"` or `"none"`. |
|
|
73
79
|
| `cert` | `None` | `(certfile, keyfile)` paths for a client certificate, used by every request unless the request overrides it. |
|
|
74
|
-
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. |
|
|
80
|
+
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. Cancelling the task (or `asyncio.wait_for`) also stops the transfer and frees its connection slot; on HTTP/1.1 that closes the connection, on HTTP/2 and HTTP/3 it resets only that stream. |
|
|
75
81
|
| `connect_timeout` | `None` | Seconds allowed to connect, TLS included. `None` means curl's default of 300 s. |
|
|
76
82
|
| `verify` | `False` | Server certificate checking. `False`: none, as most load tests want. `True`: check against the system CA bundle: `SSL_CERT_FILE` if set, otherwise libcurl's own default, or the usual system locations if it has none. A path: check against that CA bundle. Requests can override it. |
|
|
77
83
|
| `json_dumps` | `None` | Function that turns a `json=` argument into the request body (`str` or `bytes`). `None` means the engine's. |
|
|
@@ -117,7 +123,7 @@ An engine binds to the asyncio loop running when it is first used, and so does a
|
|
|
117
123
|
| `cookies` | Dict of cookies to send with this request (added to the session jar). |
|
|
118
124
|
| `cookie_list` | List of `Cookie` objects. |
|
|
119
125
|
| `auth` | `(username, password)` for basic auth. |
|
|
120
|
-
| `data` | Request body: `str` or `bytes` as is, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
126
|
+
| `data` | Request body: `str` or `bytes` as is, with no `Content-Type` unless you set one, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
121
127
|
| `json` | Object to send as JSON, encoded with the session's `json_dumps`. Sets `Content-Type: application/json` unless you set it. |
|
|
122
128
|
| `files` | Dict (or list of pairs) of files to send as `multipart/form-data`, with any `data` dict as extra fields. A value is an open file, or `(filename, content)` or `(filename, content, content_type)`, where content is `bytes`, `str` or a file. Files are read into memory. |
|
|
123
129
|
| `cert` | `(certfile, keyfile)`, overriding the session's certificate. |
|
|
@@ -146,7 +152,7 @@ Failed transfers raise `httpperf.RequestError` with curl's detailed error messag
|
|
|
146
152
|
| `text` | Body decoded with `encoding`. |
|
|
147
153
|
| `encoding` | From the `Content-Type` charset, else latin-1 (`utf-8` for JSON). Can be set. |
|
|
148
154
|
| `json()` | Body parsed with the session's `json_loads`, once. By default the standard library, always as UTF-8, as RFC 8259 requires. |
|
|
149
|
-
| `cookies`, `cookielist` | The
|
|
155
|
+
| `cookies`, `cookielist` | The cookies this response set, from its `Set-Cookie` headers, as a dict or as `Cookie` objects. The session's whole jar is `session.cookies()`. |
|
|
150
156
|
| `primary_ip` | Address connected to. |
|
|
151
157
|
| `upload_size`, `download_size` | Bytes, as integers. |
|
|
152
158
|
| `request` | The `Request`: `method`, `url`, `headers`, `cookies`, `auth`, `data`. |
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import collections.abc
|
|
3
3
|
import datetime
|
|
4
|
+
import email.utils
|
|
4
5
|
import http
|
|
5
6
|
import json as _json
|
|
6
7
|
import os
|
|
@@ -12,6 +13,7 @@ import weakref
|
|
|
12
13
|
from urllib.parse import urlencode, urlparse
|
|
13
14
|
|
|
14
15
|
from httpperf import _httpperf
|
|
16
|
+
from httpperf.version import __version__ as __version__
|
|
15
17
|
|
|
16
18
|
_json_dumps = _json.JSONEncoder(separators=(",", ":"), check_circular=False).encode
|
|
17
19
|
|
|
@@ -242,6 +244,47 @@ def _encoding_from_content_type(content_type):
|
|
|
242
244
|
return "latin1"
|
|
243
245
|
|
|
244
246
|
|
|
247
|
+
def _cookie_expiration(attrs):
|
|
248
|
+
if "max-age" in attrs:
|
|
249
|
+
try:
|
|
250
|
+
max_age = int(attrs["max-age"])
|
|
251
|
+
except ValueError:
|
|
252
|
+
return 0
|
|
253
|
+
return int(time.time()) + max_age if max_age > 0 else 1
|
|
254
|
+
if "expires" in attrs:
|
|
255
|
+
try:
|
|
256
|
+
return max(int(email.utils.parsedate_to_datetime(attrs["expires"]).timestamp()), 1)
|
|
257
|
+
except (TypeError, ValueError, IndexError, OverflowError):
|
|
258
|
+
return 0
|
|
259
|
+
return 0
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _parse_set_cookie(value, url):
|
|
263
|
+
pair, *rest = value.split(";")
|
|
264
|
+
name, sep, cookie_value = pair.partition("=")
|
|
265
|
+
if not sep or not name.strip():
|
|
266
|
+
return None
|
|
267
|
+
attrs = {}
|
|
268
|
+
for attr in rest:
|
|
269
|
+
key, _, attr_value = attr.partition("=")
|
|
270
|
+
attrs[key.strip().lower()] = attr_value.strip()
|
|
271
|
+
parsed = urlparse(url)
|
|
272
|
+
domain = attrs.get("domain", "").lstrip(".")
|
|
273
|
+
path = attrs.get("path", "")
|
|
274
|
+
if not path.startswith("/"):
|
|
275
|
+
path = parsed.path.rpartition("/")[0] or "/"
|
|
276
|
+
return Cookie(
|
|
277
|
+
"httponly" in attrs,
|
|
278
|
+
"." + domain if domain else parsed.hostname,
|
|
279
|
+
bool(domain),
|
|
280
|
+
path,
|
|
281
|
+
"secure" in attrs,
|
|
282
|
+
_cookie_expiration(attrs),
|
|
283
|
+
name.strip(),
|
|
284
|
+
cookie_value.strip(),
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
|
|
245
288
|
def _cookie_list_to_cookie_dict(cookie_list):
|
|
246
289
|
return {cookie.name: cookie.value for cookie in cookie_list}
|
|
247
290
|
|
|
@@ -271,7 +314,10 @@ class Request:
|
|
|
271
314
|
|
|
272
315
|
@property
|
|
273
316
|
def headers(self):
|
|
274
|
-
return
|
|
317
|
+
return {
|
|
318
|
+
name.strip(): value.strip()
|
|
319
|
+
for name, _, value in (header.partition(":") for header in self.header_list or ())
|
|
320
|
+
}
|
|
275
321
|
|
|
276
322
|
@property
|
|
277
323
|
def cookie_list(self):
|
|
@@ -279,7 +325,7 @@ class Request:
|
|
|
279
325
|
|
|
280
326
|
@property
|
|
281
327
|
def cookies(self):
|
|
282
|
-
return _cookie_list_to_cookie_dict(self.cookie_list)
|
|
328
|
+
return _cookie_list_to_cookie_dict(self.cookie_list or ())
|
|
283
329
|
|
|
284
330
|
@property
|
|
285
331
|
def auth(self):
|
|
@@ -452,7 +498,9 @@ class Response:
|
|
|
452
498
|
|
|
453
499
|
@property
|
|
454
500
|
def cookielist(self):
|
|
455
|
-
|
|
501
|
+
url = self.url
|
|
502
|
+
cookies = (_parse_set_cookie(v, url) for name, v in self.headers_tuple if name.lower() == "set-cookie")
|
|
503
|
+
return [cookie for cookie in cookies if cookie is not None]
|
|
456
504
|
|
|
457
505
|
@property
|
|
458
506
|
def cookies(self):
|
|
@@ -523,6 +571,16 @@ class Response:
|
|
|
523
571
|
return self._header
|
|
524
572
|
|
|
525
573
|
|
|
574
|
+
class _Future(asyncio.Future):
|
|
575
|
+
__slots__ = ("_session", "_handle")
|
|
576
|
+
|
|
577
|
+
def cancel(self, *args):
|
|
578
|
+
if not super().cancel(*args):
|
|
579
|
+
return False
|
|
580
|
+
self._session.cancel(self._handle)
|
|
581
|
+
return True
|
|
582
|
+
|
|
583
|
+
|
|
526
584
|
class Session:
|
|
527
585
|
def __init__(
|
|
528
586
|
self,
|
|
@@ -655,15 +713,10 @@ class Session:
|
|
|
655
713
|
headers_list.append("Content-Type: " + content_type)
|
|
656
714
|
|
|
657
715
|
if headers:
|
|
658
|
-
|
|
659
|
-
headers_list = []
|
|
660
|
-
headers_list.extend("%s: %s" % i for i in headers.items())
|
|
716
|
+
headers_list = list(headers_list or ()) + ["%s: %s" % i for i in headers.items()]
|
|
661
717
|
|
|
662
718
|
if cookies:
|
|
663
|
-
|
|
664
|
-
cookie_list = []
|
|
665
|
-
for k, v in cookies.items():
|
|
666
|
-
cookie_list.append(session_cookie_for_url(url, k, v))
|
|
719
|
+
cookie_list = list(cookie_list or ()) + [session_cookie_for_url(url, k, v) for k, v in cookies.items()]
|
|
667
720
|
|
|
668
721
|
return await self._request(
|
|
669
722
|
method,
|
|
@@ -704,8 +757,9 @@ class Session:
|
|
|
704
757
|
self._session.attach(engine._ae_loop)
|
|
705
758
|
if loop is not engine._loop():
|
|
706
759
|
engine._bind(loop)
|
|
707
|
-
future = loop
|
|
708
|
-
self._session
|
|
760
|
+
future = _Future(loop=loop)
|
|
761
|
+
future._session = self._session
|
|
762
|
+
future._handle = self._session.request(
|
|
709
763
|
future,
|
|
710
764
|
method,
|
|
711
765
|
url,
|
|
@@ -798,6 +852,8 @@ class Engine:
|
|
|
798
852
|
|
|
799
853
|
def _complete(self):
|
|
800
854
|
for error, response, future in self._ae_loop.get_completed():
|
|
855
|
+
if future.done():
|
|
856
|
+
continue
|
|
801
857
|
if response is not None:
|
|
802
858
|
future.set_result(response)
|
|
803
859
|
else:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0rc3"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpperf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.0rc3
|
|
4
4
|
Summary: An asyncio HTTP client for load testing, built on libcurl.
|
|
5
5
|
Author-email: Tony Simpson <agjasimpson@gmail.com>
|
|
6
6
|
Project-URL: Source, https://github.com/tonysimpson/httpperf
|
|
@@ -28,8 +28,6 @@ Dynamic: license-file
|
|
|
28
28
|
|
|
29
29
|
An asyncio HTTP client for load testing, built on libcurl.
|
|
30
30
|
|
|
31
|
-
httpperf was called acurl until version 1.0.
|
|
32
|
-
|
|
33
31
|
## Design
|
|
34
32
|
|
|
35
33
|
A load-testing client has three jobs: drive as much load as possible from each machine, report the server's response times rather than time spent waiting on the client, and read responses promptly so the server never sees a slow reader. httpperf is built around these.
|
|
@@ -52,15 +50,23 @@ Bytes are read off the wire as they arrive, whatever Python is doing. If Python
|
|
|
52
50
|
pip install httpperf
|
|
53
51
|
```
|
|
54
52
|
|
|
55
|
-
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2
|
|
53
|
+
Wheels are published for Linux on x86_64 and aarch64, for Python 3.9 to 3.15, with glibc 2.34 or later (Ubuntu 22.04, Debian 12, RHEL 9 and later) or musl (Alpine). They include their own libcurl, with HTTP/2 and HTTP/3.
|
|
56
54
|
|
|
57
|
-
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available.
|
|
55
|
+
Anywhere else, including Python 3.8, pip builds from source against the system's libcurl, which needs its development headers and a C compiler. That libcurl decides whether HTTP/3 is available: `curl -V` lists `HTTP3` under Features when it does.
|
|
58
56
|
|
|
59
57
|
```sh
|
|
60
58
|
sudo apt install libcurl4-openssl-dev # Debian/Ubuntu
|
|
61
59
|
pip install httpperf
|
|
62
60
|
```
|
|
63
61
|
|
|
62
|
+
To build against your own libcurl even where a wheel exists, skip the wheel, point the build at it and make sure it is found at run time:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
CFLAGS=-I$PREFIX/include LDFLAGS="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib" pip install --no-binary httpperf httpperf
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A session with `http_version="HTTP/3"` raises `ValueError` if the libcurl in use lacks HTTP/3.
|
|
69
|
+
|
|
64
70
|
## Quick start
|
|
65
71
|
|
|
66
72
|
```python
|
|
@@ -97,7 +103,7 @@ All arguments are keyword-only. A session can be created anywhere, even outside
|
|
|
97
103
|
| `max_host_connections` | `0` | Per-session cap on connections per host. Needs `connections="session"` or `"none"`. |
|
|
98
104
|
| `max_connections` | `0` | Per-session cap on connections in use. Needs `connections="session"` or `"none"`. |
|
|
99
105
|
| `cert` | `None` | `(certfile, keyfile)` paths for a client certificate, used by every request unless the request overrides it. |
|
|
100
|
-
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. |
|
|
106
|
+
| `timeout` | `None` | Seconds allowed for each request, from the start of the transfer to the last byte (each redirect hop separately). `None` or 0 means no limit. Cancelling the task (or `asyncio.wait_for`) also stops the transfer and frees its connection slot; on HTTP/1.1 that closes the connection, on HTTP/2 and HTTP/3 it resets only that stream. |
|
|
101
107
|
| `connect_timeout` | `None` | Seconds allowed to connect, TLS included. `None` means curl's default of 300 s. |
|
|
102
108
|
| `verify` | `False` | Server certificate checking. `False`: none, as most load tests want. `True`: check against the system CA bundle: `SSL_CERT_FILE` if set, otherwise libcurl's own default, or the usual system locations if it has none. A path: check against that CA bundle. Requests can override it. |
|
|
103
109
|
| `json_dumps` | `None` | Function that turns a `json=` argument into the request body (`str` or `bytes`). `None` means the engine's. |
|
|
@@ -143,7 +149,7 @@ An engine binds to the asyncio loop running when it is first used, and so does a
|
|
|
143
149
|
| `cookies` | Dict of cookies to send with this request (added to the session jar). |
|
|
144
150
|
| `cookie_list` | List of `Cookie` objects. |
|
|
145
151
|
| `auth` | `(username, password)` for basic auth. |
|
|
146
|
-
| `data` | Request body: `str` or `bytes` as is, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
152
|
+
| `data` | Request body: `str` or `bytes` as is, with no `Content-Type` unless you set one, or a dict or list of pairs, form-encoded with `Content-Type: application/x-www-form-urlencoded` unless you set it. |
|
|
147
153
|
| `json` | Object to send as JSON, encoded with the session's `json_dumps`. Sets `Content-Type: application/json` unless you set it. |
|
|
148
154
|
| `files` | Dict (or list of pairs) of files to send as `multipart/form-data`, with any `data` dict as extra fields. A value is an open file, or `(filename, content)` or `(filename, content, content_type)`, where content is `bytes`, `str` or a file. Files are read into memory. |
|
|
149
155
|
| `cert` | `(certfile, keyfile)`, overriding the session's certificate. |
|
|
@@ -172,7 +178,7 @@ Failed transfers raise `httpperf.RequestError` with curl's detailed error messag
|
|
|
172
178
|
| `text` | Body decoded with `encoding`. |
|
|
173
179
|
| `encoding` | From the `Content-Type` charset, else latin-1 (`utf-8` for JSON). Can be set. |
|
|
174
180
|
| `json()` | Body parsed with the session's `json_loads`, once. By default the standard library, always as UTF-8, as RFC 8259 requires. |
|
|
175
|
-
| `cookies`, `cookielist` | The
|
|
181
|
+
| `cookies`, `cookielist` | The cookies this response set, from its `Set-Cookie` headers, as a dict or as `Cookie` objects. The session's whole jar is `session.cookies()`. |
|
|
176
182
|
| `primary_ip` | Address connected to. |
|
|
177
183
|
| `upload_size`, `download_size` | Bytes, as integers. |
|
|
178
184
|
| `request` | The `Request`: `method`, `url`, `headers`, `cookies`, `auth`, `data`. |
|
|
@@ -22,11 +22,14 @@ src/ae/atomicvar.h
|
|
|
22
22
|
src/ae/config.h
|
|
23
23
|
src/ae/zmalloc.c
|
|
24
24
|
src/ae/zmalloc.h
|
|
25
|
+
tests/test_api.py
|
|
26
|
+
tests/test_cancel.py
|
|
25
27
|
tests/test_connections.py
|
|
26
28
|
tests/test_cookie.py
|
|
27
29
|
tests/test_engine.py
|
|
28
30
|
tests/test_http_versions.py
|
|
29
31
|
tests/test_httpbin.py
|
|
30
32
|
tests/test_leaks.py
|
|
33
|
+
tests/test_limiter.py
|
|
31
34
|
tests/test_response.py
|
|
32
35
|
tests/test_tls.py
|