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
NoneRelease 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.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3787c1f46e9722ef7f07ea5c76b0103037483d1b12e34a02c53ceca5afa4e09a |
|
MD5 | 57cc275b5067ee3cf98d562337336ed6 |
|
BLAKE2b-256 | 9c56662142a7e230098d3f402edf196ab0af9dbc38213c27bdfbeb396a00bda5 |
Hashes for httptools-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4687dfc116a9f1eb22a7d797f0dc6f6e17190d406ca4e729634b38aa98044b17 |
|
MD5 | fc417ec1b75be82d1a3501e2c54803fe |
|
BLAKE2b-256 | 7ceb260584e1959fd686ae5e217877e5d27d3d1c2d33d668ec9179b9d22498a4 |
Hashes for httptools-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72ee0e3fb9c6437ab3ae34e9abee67fcee6876f4f58504e3f613dd5882aafdb7 |
|
MD5 | 0fc3b265386dabf2c8f61b38a0d79390 |
|
BLAKE2b-256 | 8a72e777a09fc8361c0964771ddd06932e87a5293eb66528f81c09f4d59658b2 |
Hashes for httptools-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f475b642c48b1b78584bdd12a5143e2c512485664331eade9c29ef769a17598 |
|
MD5 | f094d814ef6fb07373557fa815a7beaa |
|
BLAKE2b-256 | 03af9fff2fe60e2c202834b524c30886a42d4eea216f159faf3f6a57a35a31d0 |
Hashes for httptools-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4137137de8976511a392e27bfdcf231bd926ac13d375e0414e927b08217d779e |
|
MD5 | 2ad4f411f8180aa3881ca69e3e3603ad |
|
BLAKE2b-256 | 5a8b6d3095f28f08fa8f3948876c55fb9b962c51ab0313dd2b6abe81c85d9026 |
Hashes for httptools-0.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2119fa619a4c53311f594f25c0205d619350fcb32140ec5057f861952e9b2b4f |
|
MD5 | 24eb950bc50b6a148f5212f48a4eef89 |
|
BLAKE2b-256 | fd4c316c91daf81e7b15b272979929d26f636bfbbc46f1df2434953112526cc2 |
Hashes for httptools-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21e948034f70e47c8abfa2d5e6f1a5661f87a2cddc7bcc70f61579cc87897c70 |
|
MD5 | 5d4abef33fee339b0382b07addefae48 |
|
BLAKE2b-256 | fc3b9319adcffc18f0f1a325f1fcba4f8aca4fefd70c81e86fb099d3d84e2470 |
Hashes for httptools-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 074afd8afdeec0fa6786cd4a1676e0c0be23dc9a017a86647efa6b695168104f |
|
MD5 | 8b816290eed350ffb773178bd4d76c17 |
|
BLAKE2b-256 | 6d701e20036c3717b9b0927bbe299f48b7476c00407ebab65ed1f58907f555ac |
Hashes for httptools-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a10a5903b5bc0eb647d01cd1e95bec3bb614a9bf53f0af1e01360b2debdf81 |
|
MD5 | 86cc4deeb4c0fc4cf0855cdd4e0df521 |
|
BLAKE2b-256 | 664958553c9e3bb1508f8483bab1cfe71e4498be968a90f1d4aa1859832c71ae |
Hashes for httptools-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8f26327023fa1a947d36e60a0582149e182fbbc949c8a65ec8665754dbbe69 |
|
MD5 | ca1cfae3dfc6d480cfa5464553d9c624 |
|
BLAKE2b-256 | 44341f56e15159222d68ff918ede8af1f23159ce6a6d19664bfc371bb5cdffc9 |
Hashes for httptools-0.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a836bd85ae1fb4304f674808488dae403e136d274aa5bafd0e6ee456f11c371 |
|
MD5 | 36b03f28a284079c2009151fda9d3f1b |
|
BLAKE2b-256 | 80f85900a68f3ba35ec24fbc048cdfc1bb8f7f93ec46f94cddbef0150a4d5a7b |
Hashes for httptools-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ac842df4fc3952efa7820b277961ea55e068bbc54cb59a0820400de7ae358d8 |
|
MD5 | e9d2174c4af6733d3be7c4eab892aa46 |
|
BLAKE2b-256 | d71173a64ec1903b8af0a21e1f2f95d80f3b6fc2b8be0759788ab9f70b1a725d |
Hashes for httptools-0.3.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47dba2345aaa01b87e4981e8756af441349340708d5b60712c98c55a4d28f4af |
|
MD5 | ebc7bfd2c3334cf71ac6c20517e01dc1 |
|
BLAKE2b-256 | 00c3d9e1b80e92ad7fc3764aa9b044bd0714e8d70635687202e79fb7af446854 |
Hashes for httptools-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc3975db86c29817e6d13df14e037c931fc893a710fb71097777a4147090068 |
|
MD5 | 6f2e29f486df07093fb7ebb5c89291e8 |
|
BLAKE2b-256 | 034af651e9f1f26aad2d54155c7b0c39bf11b64b6f02a35ded07818a1740eb1c |
Hashes for httptools-0.3.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e676bc3bb911b11f3d7e2144b9a53600bf6b9b21e0e4437aa308e1eef094d97 |
|
MD5 | ecdf070a1f94f1b3888d2057346a7b9b |
|
BLAKE2b-256 | f78da6994d218b2ea1fd7044e7f050b176ddca6f6bde49d77be377e660ddd920 |
Hashes for httptools-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04114db99605c9b56ea22a8ec4d7b1485b908128ed4f4a8f6438489c428da794 |
|
MD5 | 607c73d344a8e7f87038ab993ffc61a8 |
|
BLAKE2b-256 | e64eb97571953cb14d8b9d3a4410409964fa1471e967a55f54ed6e8ac4c608d8 |
Hashes for httptools-0.3.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 113816f9af7dcfc4aa71ebb5354d77365f666ecf96ac7ff2aa1d24b6bca44165 |
|
MD5 | b9bf823d4277f2cb5e85a8019e0c0907 |
|
BLAKE2b-256 | 4b6ced8675197a85e215f4b88c3e4223bdc22d594f7d8a01ed7636e86a40fa21 |
Hashes for httptools-0.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8ac7dee63af4346e02b1e6d32202e3b5b3706a9928bec6da6d7a5b066217422 |
|
MD5 | 6b24e3ffe1c73d823f1ce889ae2bc762 |
|
BLAKE2b-256 | 2eafa6a36bcde14f18d9ccf22986d8875bd6e2e9de7a325fdcc1fad098b9959f |
Hashes for httptools-0.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c14576b737d9e6e4f2a86af04918dbe9b62f57ce8102a8695c9a382dbe405c7f |
|
MD5 | f06a7236ee4e79fb0014abac00a9f834 |
|
BLAKE2b-256 | 7b4a051b0f4f0d42c289e78b232d42cfe603d82b1995f545eed21e065bd893ce |
Hashes for httptools-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f82eb106e1474c63dba36a176067e65b48385f4cecddf3616411aa5d1fbdfec |
|
MD5 | 32e0afe4cbbc4e631e176e519ebfd383 |
|
BLAKE2b-256 | 1151eb5faa66ae206c738720b9c58ec6869e0c9b45630ddb7d60d35e2e166ce4 |
Hashes for httptools-0.3.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79717080dc3f8b1eeb7f820b9b81528acbc04be6041f323fdd97550da2062575 |
|
MD5 | a3fd3f24fec0299f0614468afa1a7d8b |
|
BLAKE2b-256 | c3a8f2378e73ff416bcf00b35f6e68f9826265c3adbb1f4714e850035efaca15 |
Hashes for httptools-0.3.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda95634027200f4b2a6d499e7c2e7fa9b8ee57e045dfda26958ea0af27c070b |
|
MD5 | 83115769eabdd8cb472a193d3f7ed1a4 |
|
BLAKE2b-256 | 730f75413c799e19f185fe6a8d57a9fb64dc8ac4496850ccc761a47d61cca53c |
Hashes for httptools-0.3.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ac2e0ce6733c55858932e7d37fcc7b67ba6bb23e9648593c55f663de031b93 |
|
MD5 | 42614b95fa7b7d4736dfc08acbf7b78f |
|
BLAKE2b-256 | 66bca1f662d24ecd051c1438c6243d14960829c1c4f4143f60c4b513597491f5 |