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.5:
python3.5 -m venv envname
-
Activate the environment with
source envname/bin/activate
-
Install Cython with
pip install cython
-
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.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 200fc1cdf733a9ff554c0bb97a4047785cfaad9875307d6087001db3eb2b417f |
|
MD5 | 910f1dcc62b1e6fba9633d08dab4bd56 |
|
BLAKE2b-256 | d4cbc15e64f204d748533c197434afa325e48766b7045de2e4b15af198ba2338 |
Hashes for httptools-0.2.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd3b8905e21431ad306eeaf56644a68fdd621bf8f3097eff54d0f6bdf7262065 |
|
MD5 | ad01ca04a19495a6009971849479f046 |
|
BLAKE2b-256 | 100a95cacee1b444993a1c2106b4fdb890ea3a648918f7cb8744a6cd1f9591db |
Hashes for httptools-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b08d00d889a118f68f37f3c43e359aab24ee29eb2e3fe96d64c6a2ba8b9d6557 |
|
MD5 | b7bf1cac361d4b8caef8ed01853126e1 |
|
BLAKE2b-256 | 564724d1d1116ff514ecaf1f4e6f832856375df567d59191acb593ac8f818c48 |
Hashes for httptools-0.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc9be041e428c10f8b6ab358c6b393648f9457094e1dcc11b4906026d43cd380 |
|
MD5 | 5b5acef91f9c6ef855db6936b2149044 |
|
BLAKE2b-256 | 2a4285763f28626b613b470442987eccd461f3308485b1d9c528499d683b2979 |
Hashes for httptools-0.2.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 813871f961edea6cb2fe312f2d9b27d12a51ba92545380126f80d0de1917ea15 |
|
MD5 | ac524aa01cca3c1709f9794c4d3d2f6a |
|
BLAKE2b-256 | b3e7b893f9e994732e8763d8f59913cb70faaa44f41df2fa15fa1624827d8f2f |
Hashes for httptools-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a289c27ccae399a70eacf32df9a44059ca2ba4ac444604b00a19a6c1f0809943 |
|
MD5 | 0636a9f912c438ae94900a07562a62aa |
|
BLAKE2b-256 | 03d15d617f1ca8d7839963db6c30e47f5c2276a99c44ee2c2535dcbe1ffcde4c |
Hashes for httptools-0.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5682eeb10cca0606c4a8286a3391d4c3c5a36f0c448e71b8bd05be4e1694bfb |
|
MD5 | 3f15ef1fa8f6da71fbaa97a5ba40874a |
|
BLAKE2b-256 | 415a89c0f669ae9a58e6855590a0f5c0af0f37a6bea57b51b0f79b6911c0dfcb |
Hashes for httptools-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80ffa04fe8c8dfacf6e4cef8277347d35b0442c581f5814f3b0cf41b65c43c6e |
|
MD5 | 766a3db72733f5180e0290f7a7906bda |
|
BLAKE2b-256 | 4c87ebb92639705924aac5ed6aa91bd4332b20d7180f3e94bd168742e7671025 |
Hashes for httptools-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b392a166adcc8bc2f526a939a8aabf89fe079243e1543fd0e7dc1b58d737cb |
|
MD5 | 29771b47404238c14239d2db4139673a |
|
BLAKE2b-256 | d20517556eb2088d280cd3fe78e52e334cf24d052cdb27102e87eee5233fef80 |
Hashes for httptools-0.2.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7594f9a010cdf1e16a58b3bf26c9da39bbf663e3b8d46d39176999d71816658 |
|
MD5 | ed2f3861ec804c5a357fa534edc7d003 |
|
BLAKE2b-256 | 9489e88f473d8b9b0e60c9e3693fe16e4c8ef8aec67f4228e1a65e8dc6c2eb97 |
Hashes for httptools-0.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ab1f390d8867f74b3b5ee2a7ecc9b8d7f53750bd45714bf1cb72a953d7dfa77 |
|
MD5 | 267546f16d5e2b4e7b877b5a6f809bc0 |
|
BLAKE2b-256 | 818fa8238a287d1bd3455e4297a358d4cdbd1da2bfb0ec3fbfb8a254119aa8e7 |
Hashes for httptools-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a23166e5ae2775709cf4f7ad4c2048755ebfb272767d244e1a96d55ac775cca7 |
|
MD5 | dd9396cc77fc101789d969f1aa7136d4 |
|
BLAKE2b-256 | 25d0092d6d1541a37885dbf11525ca9ad2a7082714511256801961d495b529c0 |
Hashes for httptools-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78d03dd39b09c99ec917d50189e6743adbfd18c15d5944392d2eabda688bf149 |
|
MD5 | b5c2743c8c2dd94a45db6a1fdc5c5ce2 |
|
BLAKE2b-256 | aea50b450216fe120f2f92996e4c7632d8db65d1fdc574c98cfb7adb6148cc1e |
Hashes for httptools-0.2.0-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79dbc21f3612a78b28384e989b21872e2e3cf3968532601544696e4ed0007ce5 |
|
MD5 | 54a91aa1e43886dff205c92988951ec7 |
|
BLAKE2b-256 | 8e4c4d22571b5f8eba7eff92c09e46b0d360f7813c3408bc68fcdbd60d1b6e6d |