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.6.2-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf61238811a75335751b4b17f8b221a35f93f2d57489296742adf98412d2a568 |
|
MD5 | 4dcd3b2bed6942c2bfd79399d498d65b |
|
BLAKE2b-256 | 3dc7daf5b58e25cb76f9fb9ab449526bcf643996bf1553b73cbf1a3dc4530f3d |
Hashes for httptools-0.6.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c30902f9b9da0d74668b6f71d7b57081a4879d9a5ea93d5922dbe15b15b3b24a |
|
MD5 | b3c58e6ea0c1bcaab2719a9492fc8aeb |
|
BLAKE2b-256 | fa82d745afae65cb55096e3e335846694cf913f1281bb5a17c559dcb61f12282 |
Hashes for httptools-0.6.2-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fdb4634040d1dbde7e0b373e19668cdb61c0ee8690d3b4064ac748d85365bca |
|
MD5 | 6af2206b07bd8ee92ee95acede5f7385 |
|
BLAKE2b-256 | b2c76f8dec1647e770b8bb21bcd17796c4f34aae406ae68b03e9c1c971763ac8 |
Hashes for httptools-0.6.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41965586b02715c3d83dd9153001f654e5b621de0c5255f5ef0635485212d0c0 |
|
MD5 | fb60e9b7080725f8aab921ff0e721561 |
|
BLAKE2b-256 | 94488f7e1c5c48cde62f05e75ae37b9e97cc1ab86b793b2b7a89380421b46773 |
Hashes for httptools-0.6.2-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93b1839d54b80a06a51a31b90d024a1770e250d00de57e7ae069bafba932f398 |
|
MD5 | bfc187c28d313b08b3053be859f01987 |
|
BLAKE2b-256 | b12ca8abdd3602baf0cb50c1868b47401ee4ab35954d6e8832a6e7d134dda122 |
Hashes for httptools-0.6.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e22c33123ce11231ff2773d8905e20b45d77a69459def7481283b72a583955 |
|
MD5 | 6241375a7af9a9e293d537ec682d8a26 |
|
BLAKE2b-256 | acb00a760298af9fb0b93ac2a701e6ee053653b8d51ce79e8cbb1fdcd22e7156 |
Hashes for httptools-0.6.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 406f7dc5d9db68cd9ac638d14c74d077085f76b45f704d3ec38d43b842b3cb44 |
|
MD5 | 2f837ce2a9910c14fa87f37f1a526e2c |
|
BLAKE2b-256 | 9e43c42ac106d05ced270be42ea18f025dd9edd64441c8e76fb7962428e4c3de |
Hashes for httptools-0.6.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 052f7f50e4a38f069478143878371ed17937f268349bcd68f6f7a9de9fcfce21 |
|
MD5 | d6e2490274fae1f512ca163402f23473 |
|
BLAKE2b-256 | 41a2cfcc8135c675678468d5855b0522b1d33c75929aa10fb6f688cd3d2b9b84 |
Hashes for httptools-0.6.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddaf38943dbb32333a182c894b6092a68b56c5e36d0c54ba3761d28119b15447 |
|
MD5 | 742d69c94ae3984ec8fe2cf07afbfddf |
|
BLAKE2b-256 | 26601cfade9072dc534ed3d8e999ceb2b27416e6a867309b5833ea09a8664edf |
Hashes for httptools-0.6.2-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddc328c2a2daf2cf4bdc7bbc8a458dc4c840637223d4b8e01bce2168cc79fd23 |
|
MD5 | 3010869cec5983dd79ccef7f06ba1843 |
|
BLAKE2b-256 | b5d0184bc1951e72f365120c792a047db97387158bb554b4145c0c49c66f5cac |
Hashes for httptools-0.6.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56bcd9ba0adf16edb4e3e45b8b9346f5b3b2372402e953d54c84b345d0f691e0 |
|
MD5 | 94d71f112390fc6c0b20832ffafb8b5e |
|
BLAKE2b-256 | 48643b885cc0bb8d3c259134c84a9b4afdc3198be02c8314debaa26ee9729d57 |
Hashes for httptools-0.6.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e350a887adb38ac65c93c2f395b60cf482baca61fd396ed8d6fd313dbcce6fac |
|
MD5 | 3ae73d55c5c191a52cc50517c4738b61 |
|
BLAKE2b-256 | 5037da4cd7fad010d3f3ce31df79129935ed027e973515679cbf743a84e53928 |
Hashes for httptools-0.6.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78f920a75c1dbcb5a48a495f384d73ceb41e437a966c318eb7e56f1c1ad1df3e |
|
MD5 | 27587ac2d1b9c35fb8f56572cca76b13 |
|
BLAKE2b-256 | 962a01701dba88439531e0740142de2763c0180f01340a6e5285f9fffe2bbd44 |
Hashes for httptools-0.6.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92d2b7c1a914ab2f66454961eeaf904f4fe7529b93ff537619d22c18b82d070 |
|
MD5 | f8a94474ef75ad4d9bc90f2860852b24 |
|
BLAKE2b-256 | 70b4067d771e8acc38b1b3969b3ba61d4d8ea283c8265f5458ab3e07151e465a |
Hashes for httptools-0.6.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad44569b0f508e046ffe85b4a547d5b68d1548fd90767df69449cc28021ee709 |
|
MD5 | e2e7b0a8f5edb4847895c2b613ce0f2a |
|
BLAKE2b-256 | 76e645e696bceb47fdac8088d1d9fd5e8b2fac89ea72cdc842d1c4a7755011d3 |
Hashes for httptools-0.6.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d6e0ba155a1b3159551ac6b4551eb20028617e2e4bb71f2c61efed0756e6825 |
|
MD5 | 7de06d2b6d43294b1c705380c58d4611 |
|
BLAKE2b-256 | 480809c45b5a4f8df5faacbb24b7cc2fd752f8a82f13b4345c274729664a691c |
Hashes for httptools-0.6.2-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da016a0dab1fcced89dfff8537033c5dc200015e14023368f3f4a69e39b8716 |
|
MD5 | 86b852110e569b0cabb4856e0334f84c |
|
BLAKE2b-256 | c315040f87bf26980cbb9dcf5911ff3f5111e6a4190e97629acc3174e2b75500 |
Hashes for httptools-0.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d5c33d98b2311ddbe06e92b12b14de334dcfbe64ebcbb2c7a34b5c6036db512 |
|
MD5 | a30b786058729afea4b3a48005f626a8 |
|
BLAKE2b-256 | cbaf435e9c24d06e06c2cb8e6742978db29a965fc58d6aa52cec73519facfc41 |
Hashes for httptools-0.6.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53cd2d776700bf0ed0e6fb203d716b041712ea4906479031cc5ac5421ecaa7d2 |
|
MD5 | 8720ca3eefc0e7a0abadc85ace34d0e6 |
|
BLAKE2b-256 | 6ee6890714cd6d8315cf304c011b888e5ca75a885629b508ff83fa42597e93ea |
Hashes for httptools-0.6.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d49b14fcc9b12a52da8667587efa124a18e1a3eb63bbbcabf9882f4008d171d6 |
|
MD5 | d251bc2d8b046e0b577d347c80dbf9a8 |
|
BLAKE2b-256 | cd15879a614bcc33312991fe8f69b7c18734464e5ee1e510cac454206565e180 |
Hashes for httptools-0.6.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e9d225b178a6cc700c23cf2f5daf85a10f93f1db7c34e9ee4ee0bbc29ad458a |
|
MD5 | 36e0aa7b691234fbf06f79051f8372fa |
|
BLAKE2b-256 | 4378cc322f9d24d89982b87c8cd7579b787da7676a99c6d57248d5903960f346 |
Hashes for httptools-0.6.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 352a496244360deb1c1d108391d76cd6f3dd9f53ccf975a082e74c6761af30c9 |
|
MD5 | 4524f42e958d676095b2e3fba4ae4adf |
|
BLAKE2b-256 | 21a04c07e4bf01c5ca5b4285030ca1870f551af53588112e1fb053e973bc7f87 |
Hashes for httptools-0.6.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b73cda1326738eab5d60640ca0b87ac4e4db09a099423c41b59a5681917e8d1d |
|
MD5 | 7173fcca8cbb4d624a784dd686103678 |
|
BLAKE2b-256 | 79c21fcc87ead1530151ca8e805933ba50084987a21f17cc3c1c20df69127646 |
Hashes for httptools-0.6.2-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b57cb8a4a8a8ffdaf0395326ef3b9c1aba36e58a421438fc04c002a1f511db63 |
|
MD5 | ce9839b1103473b6445ef2b48ded80fe |
|
BLAKE2b-256 | 4423f8d1084490dedb155631873e2ed3e7b79be75705692e72afc4972f75de08 |
Hashes for httptools-0.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ddaf99e362ae4169f6a8b3508f3487264e0a1b1e58c0b07b86407bc9ecee831 |
|
MD5 | 77fe9527b8e6656040740c8cae73b44c |
|
BLAKE2b-256 | bc1b904c54a05d5ead9ff20ed9ff8b6ad4a85898616c930276f4b8c281c8d90a |
Hashes for httptools-0.6.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efc9d039b6b8a36b182bc60774bb5d456b8ff9ec44cf97719f2f38bb1dcdd546 |
|
MD5 | d92048e687a48f16ccd7f4e8128a3a07 |
|
BLAKE2b-256 | 288a104d80b34d1d8dc7c789465177999f7770d1f7ccb0bd9892327e3ff65e94 |
Hashes for httptools-0.6.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10d28e5597d4349390c640232c9366ddc15568114f56724fe30a53de9686b6ab |
|
MD5 | 3a9641682f1581535adab124b1e96c21 |
|
BLAKE2b-256 | 88a6f517590074510c3dd44e5916a5ac98bcc568e05b724e56a7f3314931c447 |
Hashes for httptools-0.6.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0238f07780782c018e9801d8f5f5aea3a4680a1af132034b444f677718c6fe88 |
|
MD5 | c0541cf54e402c599820103be0449595 |
|
BLAKE2b-256 | 7cbf122cca941f5bbe70a338ebce5f73e3b099b264d2efc855f8fda648f92890 |
Hashes for httptools-0.6.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4502620722b453c2c6306fad392c515dcb804dfa9c6d3b90d8926a07a7a01109 |
|
MD5 | c74d0b040d9f285be3a2520160c0fd06 |
|
BLAKE2b-256 | 133f008a2a6fd07d1b3cd5ecbe0dc46b8ffe3dc1ea6512e1a8d39fe6d0b3fb34 |
Hashes for httptools-0.6.2-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 054bdee08e4f7c15c186f6e7dbc8f0cf974b8dd1832b5f17f988faf8b12815c9 |
|
MD5 | cdb2cef75308098c873c6f8953587cc1 |
|
BLAKE2b-256 | 69a45042d9020aba8b119e6bf725ab339ebe16a665f6bc8965155a20aac52a8d |
Hashes for httptools-0.6.2-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d25f8fdbc6cc6561353c7a384d76295e6a85a4945115b8bc347855db150e8c77 |
|
MD5 | a983aede865bdb6741937b195027cb65 |
|
BLAKE2b-256 | a3a91f1f11af7cb021151fee576c0e86df64a0e47265c9e94105fb60feca12e6 |
Hashes for httptools-0.6.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4f2fea370361a90cb9330610a95303587eda9d1e69930dbbee9978eac1d5946 |
|
MD5 | fb878db14b0af91cb7961ba86cd2e2fd |
|
BLAKE2b-256 | 9b3248a4955473064bad343420e7b9dcb3915a27f643510e3962a613f7c06176 |
Hashes for httptools-0.6.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0481154c91725f7e7b729a535190388be6c7cbae3bbf0e793343ca386282312 |
|
MD5 | d108fea78d64140c041de9cf67cd2e9d |
|
BLAKE2b-256 | fecc8fd7ee21c4f80c3f6f7cd483570996b44677404ae67383d664c1bde91fca |
Hashes for httptools-0.6.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e45d004531330030f7d07abe4865bc17963b9989bc1941cebbf7224010fb82 |
|
MD5 | 8ffda34ad1685ecb0aeb8f2bf18ab2ff |
|
BLAKE2b-256 | 2558df27055f9cc01367ca11d3a17c73629dfc3d1720a328de924a0e5d2c6da9 |
Hashes for httptools-0.6.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1099f73952e18c718ccaaf7a97ae58c94a91839c3d247c6184326f85a2eda7b4 |
|
MD5 | 1e7cd25ffcf0436f3975a9f30a18b1eb |
|
BLAKE2b-256 | 114c3a92546b473a85c48f7f754a29214b1da3dc9b06ed94ee6ac05b461a82a1 |
Hashes for httptools-0.6.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f0246ca7f78fa8e3902ddb985b9f55509d417a862f4634a8fa63a7a496266c8 |
|
MD5 | d2e13d86c656894cba78382888376304 |
|
BLAKE2b-256 | 945ca3e56c6205ffbfed3342bdf18e2651e2ceca0bc451a7783200b146103f48 |
Hashes for httptools-0.6.2-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a5715b1f46e9852442f496c0df2f8c393cc8f293f5396d2c8d95cac852fb51 |
|
MD5 | 6f4850a8a7dd4773bbaed7530c7dd152 |
|
BLAKE2b-256 | 269d476cc91080c22a6e39fb20fbb40dbf6722c016c355313f338669dd4079fb |
Hashes for httptools-0.6.2-cp38-cp38-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b7bc59362143dc2d02896dde94004ef54ff1989ceedf4b389ad3b530f312364 |
|
MD5 | 3b89746ff55472f72070968a317d3e21 |
|
BLAKE2b-256 | 8f8238ee3c6dd74b9c51fc820c0c6ed8fd8ffd3f71daddc6a8e92d44d6c4977c |
Hashes for httptools-0.6.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bb67d47f045f56e9a5da4deccf710bdde21212e4b1f4776b7a542449f6a7682 |
|
MD5 | d06a35d84fa84ff5c173dce6a6b57e7c |
|
BLAKE2b-256 | 63b98cf3bc8b135a747f14676ac6206e19bc8ea5bb5317ad9d4237213a27e029 |
Hashes for httptools-0.6.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76dcb8f5c866f1537ccbaad01ebb3611890d281ef8d25e050d1cc3d90fba6b3d |
|
MD5 | 063d35898ce497e4e8037294f422dc8c |
|
BLAKE2b-256 | 7690d5f5ba3bd4dbeb085bd3155bd3d56ce75070985ab28feb97058283f96a9c |
Hashes for httptools-0.6.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5141ccc9dbd8cdc59d1e93e318d405477a940dc6ebadcb8d9f8da17d2812d353 |
|
MD5 | 64846cf13053209e27032de2e860206b |
|
BLAKE2b-256 | 9efcc4f02c231406b800cd173ff441e56bd12102d8f635407cc8ef8f7a193789 |
Hashes for httptools-0.6.2-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d80878cb40ebf88a48839ff7206ceb62e4b54327e0c2f9f15ee12edbd8b907e |
|
MD5 | 0928abc8a7cd31bebfda2a6af731f11a |
|
BLAKE2b-256 | 2842a0e38bf3520dc88e4b61d17cda3938f8b7eb1615d95e858dbd37dfb3ba8f |