A collection of framework independent HTTP protocol utils.
Project description
httptools is a Python binding for the nodejs HTTP parser.
The package is available on PyPI: pip install httptools
.
APIs
httptools contains two classes httptools.HttpRequestParser
,
httptools.HttpResponseParser
(fulfilled through
llhttp) and a function for
parsing URLs httptools.parse_url
(through
http-parse for now).
See unittests for examples.
class HttpRequestParser:
def __init__(self, protocol):
"""HttpRequestParser
protocol -- a Python object with the following methods
(all optional):
- on_message_begin()
- on_url(url: bytes)
- on_header(name: bytes, value: bytes)
- on_headers_complete()
- on_body(body: bytes)
- on_message_complete()
- on_chunk_header()
- on_chunk_complete()
- on_status(status: bytes)
"""
def get_http_version(self) -> str:
"""Return an HTTP protocol version."""
def should_keep_alive(self) -> bool:
"""Return ``True`` if keep-alive mode is preferred."""
def should_upgrade(self) -> bool:
"""Return ``True`` if the parsed request is a valid Upgrade request.
The method exposes a flag set just before on_headers_complete.
Calling this method earlier will only yield `False`.
"""
def feed_data(self, data: bytes):
"""Feed data to the parser.
Will eventually trigger callbacks on the ``protocol``
object.
On HTTP upgrade, this method will raise an
``HttpParserUpgrade`` exception, with its sole argument
set to the offset of the non-HTTP data in ``data``.
"""
def get_method(self) -> bytes:
"""Return HTTP request method (GET, HEAD, etc)"""
class HttpResponseParser:
"""Has all methods except ``get_method()`` that
HttpRequestParser has."""
def get_status_code(self) -> int:
"""Return the status code of the HTTP response"""
def parse_url(url: bytes):
"""Parse URL strings into a structured Python object.
Returns an instance of ``httptools.URL`` class with the
following attributes:
- schema: bytes
- host: bytes
- port: int
- path: bytes
- query: bytes
- fragment: bytes
- userinfo: bytes
"""
Development
-
Clone this repository with
git clone --recursive git@github.com:MagicStack/httptools.git
-
Create a virtual environment with Python 3:
python3 -m venv envname
-
Activate the environment with
source envname/bin/activate
-
Install development requirements with
pip install -e .[test]
-
Run
make
andmake test
.
License
MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for httptools-0.4.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d1fe6b6661022fd6cac541f54a4237496b246e6f1c0a6b41998ee08a1135afe |
|
MD5 | 0b748b91b559e66b72e2c5f5f99b61bb |
|
BLAKE2b-256 | e6c39e00700867e0aaeadd7ab84a48e73f9ed95202213e1c9a1452e80255ebe7 |
Hashes for httptools-0.4.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7af6bdbd21a2a25d6784f6d67f44f5df33ef39b6159543b9f9064d365c01f919 |
|
MD5 | bf35ec2f84e5de97e5181d3ebbccd1b2 |
|
BLAKE2b-256 | 723fe5ee5312d4b1433ed5582c2194b843c984cfac82e284006773f82afd1587 |
Hashes for httptools-0.4.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe829275cdd4174b4c4e65ad718715d449e308d59793bf3a931ee1bf7e7b86c |
|
MD5 | a64930e06f265b0d1fbeedb0b59c397f |
|
BLAKE2b-256 | 4d7beb5db4c7dee881957e6f0c476bb3aba3423a20c3ced63213ca7be469ffdd |
Hashes for httptools-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceafd5e960b39c7e0d160a1936b68eb87c5e79b3979d66e774f0c77d4d8faaed |
|
MD5 | 38122529123876bcb65cbc1324ed8574 |
|
BLAKE2b-256 | 4ea3ab51fe805d8258785f31901bc9c9d5c4eda39b32ff96363993f53a531585 |
Hashes for httptools-0.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb9f9ed79bc6f46b021b3319184699ba1a22410a82204e6e89c774530069683 |
|
MD5 | edeeddaf06f4f91ba22025da5187b96f |
|
BLAKE2b-256 | e1da25befb6a499a6025adbfef7bece2d73b20fb07377cbd792632a79015582d |
Hashes for httptools-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ee0b459257e222b878a6c09ccf233957d3a4dcb883b0847640af98d2d9aac23 |
|
MD5 | 2f61e1733dfbe66b7525c05834528e3a |
|
BLAKE2b-256 | 46cbeb418f48d511159ad296692ec473212eb98bf20e374751baf04569dac71a |
Hashes for httptools-0.4.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcddfe70553be717d9745990dfdb194e22ee0f60eb8f48c0794e7bfeda30d2d5 |
|
MD5 | 0d64b17a771c31c2366a6b9a9b4c9138 |
|
BLAKE2b-256 | 9d8ea139cea58b765108b8213596c9b7c5d9db523186363fc0c99b6fa1708da6 |
Hashes for httptools-0.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34d2903dd2a3dd85d33705b6fde40bf91fc44411661283763fd0746723963c83 |
|
MD5 | ad4bcedc777524671f0d13762d2e7942 |
|
BLAKE2b-256 | 18a911400a2843e09771ced7328ab18d4d4313176a9fd278981a33270a35663c |
Hashes for httptools-0.4.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645373c070080e632480a3d251d892cb795be3d3a15f86975d0f1aca56fd230d |
|
MD5 | 442cfd4905ad606f587e2752637734d2 |
|
BLAKE2b-256 | 6f4b059fbfb1f895cc6f008125d5c6d10dfb33296ce6009541cf3e61ee786ebb |
Hashes for httptools-0.4.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a99346ebcb801b213c591540837340bdf6fd060a8687518d01c607d338b7424 |
|
MD5 | a3e2ad1f1ffc390ef7039c3afaa5a481 |
|
BLAKE2b-256 | f821c93044f18f80bafea7fce64813f1584b11c5c05a2facf8e69fb1c6bbb131 |
Hashes for httptools-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98993805f1e3cdb53de4eed02b55dcc953cdf017ba7bbb2fd89226c086a6d855 |
|
MD5 | 0f89cfd364a8e559f197316aab83ff9d |
|
BLAKE2b-256 | 10f5592959ed892f97eb65a51d95c95839ffc980176c02f22371b2f6e7948140 |
Hashes for httptools-0.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9b90bf58f3ba04e60321a23a8723a1ff2a9377502535e70495e5ada8e6e6722 |
|
MD5 | d7b2f07a7d9b24d3e8b6db7a01277983 |
|
BLAKE2b-256 | 2de8cb6d55470a1340b97590849fa32f144221c8e5f847337bf2cc022c992c3f |
Hashes for httptools-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29bf97a5c532da9c7a04de2c7a9c31d1d54f3abd65a464119b680206bbbb1055 |
|
MD5 | 40da4e3edc83cc34613f980e8ea861c4 |
|
BLAKE2b-256 | 39f58abe985cd4e077b672c56bb4c1ab592f2d48581ce81533d54dd714c43d1e |
Hashes for httptools-0.4.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f72b5d24d6730035128b238decdc4c0f2104b7056a7ca55cf047c106842ec890 |
|
MD5 | 34838e7e42f985d3a102bcd0193a66c0 |
|
BLAKE2b-256 | b2cec48aae9a049e2e8d5f6019a1990afddee82b344915ecc277cca769730d40 |
Hashes for httptools-0.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9967d9758df505975913304c434cb9ab21e2c609ad859eb921f2f615a038c8de |
|
MD5 | 4985e418227e97afb504fb93c97e6f69 |
|
BLAKE2b-256 | 4795487a47f020730ebfbbd8e7ec64ed4bf431e0e825becd87f3ad171a0c27a7 |
Hashes for httptools-0.4.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72aa3fbe636b16d22e04b5a9d24711b043495e0ecfe58080addf23a1a37f3409 |
|
MD5 | 510786a579e7720110ff62ced0529958 |
|
BLAKE2b-256 | c5da6087458e02c6f8592ee82bc6c14d34c6d1425aa4c6bab81494cd91588ca3 |
Hashes for httptools-0.4.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3a4e165ca6204f34856b765d515d558dc84f1352033b8721e8d06c3e44930c3 |
|
MD5 | 43e3e219d2acd5d35844c2005869e3fb |
|
BLAKE2b-256 | c36e696f20a06a696aa7aece8988bf11e04f80d9ac53380e148517b82832c35f |
Hashes for httptools-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db44a0b294d317199e9f80123e72c6b005c55b625b57fae36de68670090fa48 |
|
MD5 | 8edbc16a497adb64371a1e98189c52c7 |
|
BLAKE2b-256 | ba87ee99d2aeb0174f92cc14bb9e92e04584744905d34a5c8c0e8ae702829ff5 |
Hashes for httptools-0.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c286985b5e194ca0ebb2908d71464b9be8f17cc66d6d3e330e8d5407248f56ad |
|
MD5 | 30777626404d143a28679773d50d9418 |
|
BLAKE2b-256 | 8804143e21976aecd57ce4a337297ca04490ceb674f59c601b4d0e8940c3be9c |
Hashes for httptools-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a522d12e2ddbc2e91842ffb454a1aeb0d47607972c7d8fc88bd0838d97fb8a2a |
|
MD5 | 05b83f8e129763c524a4d0d861c641ab |
|
BLAKE2b-256 | 11220dc536cb54e68f2175058d1091af12de9467062e58bc66015b0e5cc05a94 |
Hashes for httptools-0.4.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f7bfb74718f52d5ed47d608d507bf66d3bc01d4a8b3e6dd7134daaae129357b |
|
MD5 | 88a21293be026c534333a7e016b6c77b |
|
BLAKE2b-256 | d0c7b2906a24a8f98a40d7e8c79e1ed0857ede7dffc6cb78a4016113c14c42d0 |
Hashes for httptools-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f27bb0f75bef722d6e22dc609612bfa2f994541621cd2163f8c943b6463dfe |
|
MD5 | 6fbb15a917046d63b388eb51105601f0 |
|
BLAKE2b-256 | 49d41a4fdcdaa8c2c162280d748be6612adfa94870788983b9b44272aa8e4675 |
Hashes for httptools-0.4.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20a45bcf22452a10fa8d58b7dbdb474381f6946bf5b8933e3662d572bc61bae4 |
|
MD5 | b43d25e51b544a87e5ecbd3db81e98fe |
|
BLAKE2b-256 | d53f33c2feeef57b57a87c535ab36a8944a8b9e34db10f7cb2080b237e1f4903 |
Hashes for httptools-0.4.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd1295f52971097f757edfbfce827b6dbbfb0f7a74901ee7d4933dff5ad4c9af |
|
MD5 | 187117d5130229651d54e4d179c7a01d |
|
BLAKE2b-256 | 3e67ff7e1e588d358ef48b46739a3f221e09aaf5fca5f855623f0c8ff534c2d9 |
Hashes for httptools-0.4.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54bbd295f031b866b9799dd39cb45deee81aca036c9bff9f58ca06726f6494f1 |
|
MD5 | 6f6b557579a9442b66093dac03e41bed |
|
BLAKE2b-256 | 8204c4fb26ea1c73a7b0a9accea2be777b08d115aca50c882d64496416853fb4 |
Hashes for httptools-0.4.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3194f6d6443befa8d4db16c1946b2fc428a3ceb8ab32eb6f09a59f86104dc1a0 |
|
MD5 | 769c9b72ea0334da6d897a90ad57bcba |
|
BLAKE2b-256 | 73ca0a6a04ac82f202682abd8ce56dfeca7b011245352d024163274bd810126a |
Hashes for httptools-0.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 903f739c9fb78dab8970b0f3ea51f21955b24b45afa77b22ff0e172fc11ef111 |
|
MD5 | 581ccf387603c14da74171b302d542a0 |
|
BLAKE2b-256 | 1f64ff5d514d46e7876e768cdd4f2ab1df36b86907956e2e00892306aa2577bf |
Hashes for httptools-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1a7dfc1f9c78a833e2c4904757a0f47ce25d08634dd2a52af394eefe5f9777 |
|
MD5 | e0885e2bc975e0fec739187bdb1a5397 |
|
BLAKE2b-256 | a42676de3d05de3f9825941f8c1d699f23538715ba2eb61ddea4769198826232 |
Hashes for httptools-0.4.0-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 701e66b59dd21a32a274771238025d58db7e2b6ecebbab64ceff51b8e31527ae |
|
MD5 | 4720d82eced8d63998bdca7e85ce8ad0 |
|
BLAKE2b-256 | 32d1e568cc7d5b71df06b03d2c02321996c724a865f3073bf6bccce983c1ff46 |
Hashes for httptools-0.4.0-cp36-cp36m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee9f226acab9085037582c059d66769862706e8e8cd2340470ceb8b3850873d |
|
MD5 | 19b37ad8f92e0c43188954ff15c84d5f |
|
BLAKE2b-256 | faad34d08fc56b2777c5205f218ebf982442a08d015b5b24e5f1e48680884afc |
Hashes for httptools-0.4.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a113789e53ac1fa26edf99856a61e4c493868e125ae0dd6354cf518948fbbd5c |
|
MD5 | da575d6a2aeb170b228c8c0770e26a37 |
|
BLAKE2b-256 | 94f603ccc64c551d0fddbe33bed2158bdfb31be2d8ee990569bbd72721fc3849 |
Hashes for httptools-0.4.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e2eb957787cbb614a0f006bfc5798ff1d90ac7c4dd24854c84edbdc8c02369e |
|
MD5 | 18d66d23fa60efaa6cee56f001942fdc |
|
BLAKE2b-256 | f72e1dd15fe801e2e7952977ed9139ed05185765ad3bd01f23a3359175efc429 |
Hashes for httptools-0.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48e48530d9b995a84d1d89ae6b3ec4e59ea7d494b150ac3bbc5e2ac4acce92cd |
|
MD5 | b0b1faf1aa0c673edcd4e248d0bc1e66 |
|
BLAKE2b-256 | 2b8e59b5b4c672b3f8eb7f1c250de9f8b8c3f0d70519bbbbdcb8b09331c3a5ba |