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.4-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28908df1b9bb8187393d5b5db91435ccc9c8e891657f9cbb42a2541b44c82fc8 |
|
MD5 | a2e04a6a12f99539b7020b7968872caf |
|
BLAKE2b-256 | 4ddc7decab5c404d1d2cdc1bb330b1bf70e83d6af0396fd4fc76fc60c0d522bf |
Hashes for httptools-0.6.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b36913ba52008249223042dca46e69967985fb4051951f94357ea681e1f5dc0 |
|
MD5 | ec204d1f2dc9c4f3d7a704b63b9b6b43 |
|
BLAKE2b-256 | 1e6a787004fdef2cabea27bad1073bf6a33f2437b4dbd3b6fb4a9d71172b1c7c |
Hashes for httptools-0.6.4-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 342dd6946aa6bda4b8f18c734576106b8a31f2fe31492881a9a160ec84ff4bd5 |
|
MD5 | 461a922d5cb139bda6c146fec5bb32d1 |
|
BLAKE2b-256 | 8a0a0d4df132bfca1507114198b766f1737d57580c9ad1cf93c1ff673e3387be |
Hashes for httptools-0.6.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 322d20ea9cdd1fa98bd6a74b77e2ec5b818abdc3d36695ab402a0de8ef2865a3 |
|
MD5 | 4724ace84e09fbd23a5cf334da5b7979 |
|
BLAKE2b-256 | 96c1cb499655cbdbfb57b577734fde02f6fa0bbc3fe9fb4d87b742b512908dff |
Hashes for httptools-0.6.4-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d87b29bd4486c0093fc64dea80231f7c7f7eb4dc70ae394d70a495ab8436071 |
|
MD5 | 39e2eafa2ea80c1d130078017d736826 |
|
BLAKE2b-256 | af71ee32fd358f8a3bb199b03261f10921716990808a675d8160b5383487a317 |
Hashes for httptools-0.6.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 856f4bc0478ae143bad54a4242fccb1f3f86a6e1be5548fecfd4102061b3a083 |
|
MD5 | 3f521fb4bd4555763808e49fb26f2ab6 |
|
BLAKE2b-256 | ead982d5e68bab783b632023f2fa31db20bebb4e89dfc4d2293945fd68484ee4 |
Hashes for httptools-0.6.4-cp313-cp313-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade273d7e767d5fae13fa637f4d53b6e961fb7fd93c7797562663f0171c26660 |
|
MD5 | 80e96dc04ea9d7f29e869f5908e598b4 |
|
BLAKE2b-256 | 94a39fe9ad23fd35f7de6b91eeb60848986058bd8b5a5c1e256f5860a160cc3e |
Hashes for httptools-0.6.4-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db78cb9ca56b59b016e64b6031eda5653be0589dba2b1b43453f6e8b405a0970 |
|
MD5 | dbdfe28d6ddb8c6c34ca71d1d47f922c |
|
BLAKE2b-256 | 12b75cae71a8868e555f3f67a50ee7f673ce36eac970f029c0c5e9d584352961 |
Hashes for httptools-0.6.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9eb89ecf8b290f2e293325c646a211ff1c2493222798bb80a530c5e7502494f |
|
MD5 | 41ff20062eb9e9bebf18b8f057ef74a2 |
|
BLAKE2b-256 | 5f3c4aee161b4b7a971660b8be71a92c24d6c64372c1ab3ae7f366b3680df20f |
Hashes for httptools-0.6.4-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec4f178901fa1834d4a060320d2f3abc5c9e39766953d038f1458cb885f47e81 |
|
MD5 | 0a7ce69b81c98c759221c8f993054d7f |
|
BLAKE2b-256 | 52d8254d16a31d543073a0e57f1c329ca7378d8924e7e292eda72d0064987486 |
Hashes for httptools-0.6.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69422b7f458c5af875922cdb5bd586cc1f1033295aa9ff63ee196a87519ac8e1 |
|
MD5 | 1eda86d40d7b9791b36663e5084584c6 |
|
BLAKE2b-256 | 9b016fb20be3196ffdc8eeec4e653bc2a275eca7f36634c86302242c4fbb2760 |
Hashes for httptools-0.6.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16e603a3bff50db08cd578d54f07032ca1631450ceb972c2f834c2b860c28ea2 |
|
MD5 | fb459e5b5135b59877b35432eb2270bc |
|
BLAKE2b-256 | f7d8b644c44acc1368938317d76ac991c9bba1166311880bcc0ac297cb9d6bd7 |
Hashes for httptools-0.6.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85071a1e8c2d051b507161f6c3e26155b5c790e4e28d7f236422dbacc2a9cc44 |
|
MD5 | 129b557402829c3cef66fbe1a80b8407 |
|
BLAKE2b-256 | e2b8412a9bb28d0a8988de3296e01efa0bd62068b33856cdda47fe1b5e890954 |
Hashes for httptools-0.6.4-cp312-cp312-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df017d6c780287d5c80601dafa31f17bddb170232d85c066604d8558683711a2 |
|
MD5 | f855d6b060e8e4f48b2bbc098fcadb19 |
|
BLAKE2b-256 | bb0ed0b71465c66b9185f90a091ab36389a7352985fe857e352801c39d6127c8 |
Hashes for httptools-0.6.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 288cd628406cc53f9a541cfaf06041b4c71d751856bab45e3702191f931ccd17 |
|
MD5 | dad93cb243a21270584fe5c986bdd302 |
|
BLAKE2b-256 | d0464d8e7ba9581416de1c425b8264e2cadd201eb709ec1584c381f3e98f51c1 |
Hashes for httptools-0.6.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dacdd3d10ea1b4ca9df97a0a303cbacafc04b5cd375fa98732678151643d4988 |
|
MD5 | 3fd91fa032bf00f68fab68450e2724ef |
|
BLAKE2b-256 | 3ed284c9e23edbccc4a4c6f96a1b8d99dfd2350289e94f00e9ccc7aadde26fb5 |
Hashes for httptools-0.6.4-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a5ec98d3f49904b9fe36827dcf1aadfef3b89e2bd05b0e35e94f97c2b14721 |
|
MD5 | 4200445e2d1cdee74164709e68516e34 |
|
BLAKE2b-256 | 6e4cd09ce0eff09057a206a74575ae8f1e1e2f0364d20e2442224f9e6612c8b9 |
Hashes for httptools-0.6.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8787367fbdfccae38e35abf7641dafc5310310a5987b689f4c32cc8cc3ee975 |
|
MD5 | 057187416e6d7c78c6ea69a78f6c4e03 |
|
BLAKE2b-256 | b7240fe235d7b69c42423c7698d086d4db96475f9b50b6ad26a718ef27a0bce6 |
Hashes for httptools-0.6.4-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40b0f7fe4fd38e6a507bdb751db0379df1e99120c65fbdc8ee6c1d044897a636 |
|
MD5 | ce1eeb220d8ddfc4524e40de37c1758a |
|
BLAKE2b-256 | b12f205d1f2a190b72da6ffb5f41a3736c26d6fa7871101212b15e9b5cd8f61d |
Hashes for httptools-0.6.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0614154d5454c21b6410fdf5262b4a3ddb0f53f1e1721cfd59d55f32138c578a |
|
MD5 | c75470e131446c4dde4bbe94575e42f9 |
|
BLAKE2b-256 | a6173e0d3e9b901c732987a45f4f94d4e2c62b89a041d93db89eafb262afd8d5 |
Hashes for httptools-0.6.4-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f47f8ed67cc0ff862b84a1189831d1d33c963fb3ce1ee0c65d3b0cbe7b711069 |
|
MD5 | 43a923680dccbb63ce3920fe3e9a9c95 |
|
BLAKE2b-256 | 7b26bb526d4d14c2774fe07113ca1db7255737ffbb119315839af2065abfdac3 |
Hashes for httptools-0.6.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c26f313951f6e26147833fc923f78f95604bbec812a43e5ee37f26dc9e5a686c |
|
MD5 | 0b572b38a8dba1350416bacc2292813c |
|
BLAKE2b-256 | 7573187a3f620ed3175364ddb56847d7a608a6fc42d551e133197098c0143eca |
Hashes for httptools-0.6.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59e724f8b332319e2875efd360e61ac07f33b492889284a3e05e6d13746876f4 |
|
MD5 | f7b9b5eac966ff685cee991a30f339d1 |
|
BLAKE2b-256 | 8186ced96e3179c48c6f656354e106934e65c8963d48b69be78f355797f0e1b3 |
Hashes for httptools-0.6.4-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90d96a385fa941283ebd231464045187a31ad932ebfa541be8edf5b3c2328959 |
|
MD5 | 1837605417fba050fd619150e9eba9fd |
|
BLAKE2b-256 | ea9e270b7d767849b0c96f275c695d27ca76c30671f8eb8cc1bab6ced5c5e1d0 |
Hashes for httptools-0.6.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deee0e3343f98ee8047e9f4c5bc7cedbf69f5734454a94c38ee829fb2d5fa3c1 |
|
MD5 | c3d1dc70d39e5e563ad4425c914c0303 |
|
BLAKE2b-256 | 925eb4a826fe91971a0b68e8c2bd4e7db3e7519882f5a8ccdb1194be2b3ab98f |
Hashes for httptools-0.6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca80b7485c76f768a3bc83ea58373f8db7b015551117375e4918e2aa77ea9b50 |
|
MD5 | 4435c8720e36ebb10836dffba438b2e2 |
|
BLAKE2b-256 | b051ce61e531e40289a681a463e1258fa1e05e0be54540e40d91d065a264cd8f |
Hashes for httptools-0.6.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 345c288418f0944a6fe67be8e6afa9262b18c7626c3ef3c28adc5eabc06a68da |
|
MD5 | d550ac592cd0c1a63df0cfc159085a20 |
|
BLAKE2b-256 | 6ab017c672b4bc5c7ba7f201eada4e96c71d0a59fbc185e60e42580093a86f21 |
Hashes for httptools-0.6.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c73ce323711a6ffb0d247dcd5a550b8babf0f757e86a52558fe5b86d6fefcc0 |
|
MD5 | 7bb527305b1f1333216c6375f370765c |
|
BLAKE2b-256 | 3b6f972f8eb0ea7d98a1c6be436e2142d51ad2a64ee18e02b0e7ff1f62171ab1 |
Hashes for httptools-0.6.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b799de31416ecc589ad79dd85a0b2657a8fe39327944998dea368c1d4c9e55e6 |
|
MD5 | 234fa0d8dc8492d9f646acb49d8593e4 |
|
BLAKE2b-256 | 05722ddc2ae5f7ace986f7e68a326215b2e7c32e32fd40e6428fa8f1d8065c7e |
Hashes for httptools-0.6.4-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e563e54979e97b6d13f1bbc05a96109923e76b901f786a5eae36e99c01237bd |
|
MD5 | c6867003fa617c54e52f9a9574784ba6 |
|
BLAKE2b-256 | fcb33a1bc45be03dda7a60c7858e55b6cd0489a81613c1908fb81cf21d34ae50 |
Hashes for httptools-0.6.4-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aafe0f1918ed07b67c1e838f950b1c1fabc683030477e60b335649b8020e1076 |
|
MD5 | 4e60364dd5a0c3f19b9e141fe66782cf |
|
BLAKE2b-256 | 2a1368337d3be6b023260139434c49d7aa466aaa98f9aee7ed29270ac7dde6a2 |
Hashes for httptools-0.6.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1ffd262a73d7c28424252381a5b854c19d9de5f56f075445d33919a637e3547 |
|
MD5 | 1258dbaa260aa7fafae5028f3b5bdaf0 |
|
BLAKE2b-256 | dc24c70c34119d209bf08199d938dc9c69164f585ed3029237b4bdb90f673cb9 |
Hashes for httptools-0.6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 703c346571fa50d2e9856a37d7cd9435a25e7fd15e236c397bf224afaa355fe9 |
|
MD5 | e038412368d8d85681b77dda2a2e5ad0 |
|
BLAKE2b-256 | 2b62e7f317fed3703bd81053840cacba4e40bcf424b870e4197f94bd1cf9fe7a |
Hashes for httptools-0.6.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db353d22843cf1028f43c3651581e4bb49374d85692a85f95f7b9a130e1b2cab |
|
MD5 | c332aed67c626983ae51e1b9db9be570 |
|
BLAKE2b-256 | c201e6ecb40ac8fdfb76607c7d3b74a41b464458d5c8710534d8f163b0c15f29 |
Hashes for httptools-0.6.4-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85797e37e8eeaa5439d33e556662cc370e474445d5fab24dcadc65a8ffb04003 |
|
MD5 | 46d5ce2689b4c872a3c7fce436835041 |
|
BLAKE2b-256 | 51b14fc6f52afdf93b7c4304e21f6add9e981e4f857c2fa622a55dfe21b6059e |
Hashes for httptools-0.6.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df959752a0c2748a65ab5387d08287abf6779ae9165916fe053e68ae1fbdc47f |
|
MD5 | 727fc4e337502e802a4268a4a0ffd667 |
|
BLAKE2b-256 | a359b7dc35b45ae31d692427f15870ff9ab082e667b96c5606fda2cd7b385687 |
Hashes for httptools-0.6.4-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d54efd20338ac52ba31e7da78e4a72570cf729fac82bc31ff9199bedf1dc7440 |
|
MD5 | ba67a97982d7b887657b28bd63af10eb |
|
BLAKE2b-256 | d42b618e8f2cf8b266a046c4524f4c214919762a9da4617e8b02da406e3747bc |
Hashes for httptools-0.6.4-cp38-cp38-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc411e1c0a7dcd2f902c7c48cf079947a7e65b5485dea9decb82b9105ca71a43 |
|
MD5 | 5ea4efc4b2dd0a8ff2adc49121fd182c |
|
BLAKE2b-256 | 3392f0928f8bae0a07d75bddff71835e554762974502165ea5ea78c624e3533e |
Hashes for httptools-0.6.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40dc6a8e399e15ea525305a2ddba998b0af5caa2566bcd79dcbe8948181eeaff |
|
MD5 | 82916d276c2b5ed4d09e3813249fb8ec |
|
BLAKE2b-256 | 32c63623958d7899c439d5aeadcc936c3354baaf2d797e07670ccddbae5c4398 |
Hashes for httptools-0.6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab9ba8dcf59de5181f6be44a77458e45a578fc99c31510b8c65b7d5acc3cf490 |
|
MD5 | 3c2001e69babf52e875f559123aed5a8 |
|
BLAKE2b-256 | a0cf3de90444de495cbab24e648278a4fecb36c5bbf9ecdeeff09fca69e94ca9 |
Hashes for httptools-0.6.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94978a49b8f4569ad607cd4946b759d90b285e39c0d4640c6b36ca7a3ddf2efc |
|
MD5 | dd1881b44b0dd098601541e3ca0e91cf |
|
BLAKE2b-256 | 040624f105db5254d9689d9126ca09cd55c471241f26549041f33aea91a4c77e |
Hashes for httptools-0.6.4-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3f0d369e7ffbe59c4b6116a44d6a8eb4783aae027f2c0b366cf0aa964185dba |
|
MD5 | 62f8a31875ef6778ece5b7ccbc6ebee1 |
|
BLAKE2b-256 | c273e4877dfa233da9912062e49efd74d9f5deae95b4b736eb99742f8d751074 |