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.3-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8837d80715caf954c5e3c0076108a1472abe1931aee46d323056a17269ce7355 |
|
MD5 | d68b4f03b12707ab1ffb5ddd22b7a640 |
|
BLAKE2b-256 | 916aaaa6de10aebfa5519f9a1327ccc210a7f58fc513cca9445840121492bbc7 |
Hashes for httptools-0.6.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ccc1695d6b130f486780e0c8ec1c71849caf88497186f4298c7132141546d3c |
|
MD5 | 224705adbdc4437e039d62abce78c12c |
|
BLAKE2b-256 | 560deef33adb7c522f75d261b7ed90fedd47e05b8050ab1e859458f025621c69 |
Hashes for httptools-0.6.3-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb9acdaea5cf01b6e30f9db3adb2030448fb40400cd629b5943224c120f6bdde |
|
MD5 | bde4ca2e8593fe49d9808c8c88ebf66b |
|
BLAKE2b-256 | 27cc32d6cd905e36b5a63b98f3ff51f296f5edb2d31ae477a4bc82fa04ec2d45 |
Hashes for httptools-0.6.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607d11c3842d6bf7700489d3c9aeb7129b9dcb0f4817ee2c86f9780483576ecf |
|
MD5 | 35bed344eaf8a8689a717c95260d2bd6 |
|
BLAKE2b-256 | e2280827564bd2e9ff349c4dfb978fb1d86f2d36ccd383e19c418c97e3761ba8 |
Hashes for httptools-0.6.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca36dc92d44a912452e8bbf60cb1c96bbbf0cfaa484bd23f144442d5221092b |
|
MD5 | 3df81e7a547d15d3fde10af844d6726f |
|
BLAKE2b-256 | 25e8bf3ca567e5894764764377c0cdef308ec17a0cceebc1c03009f1a6df64bd |
Hashes for httptools-0.6.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b2476d3ebea1ebaa1d820a0ac1f36a83fcf96c5ad1e1bd1e79853f99c8f373 |
|
MD5 | 37af13c7042d1454451a642ac7a2ebc0 |
|
BLAKE2b-256 | a49094e0153beb03c31fb863ec4d7747ebda9ebad8a1e6a069ea324abc18807d |
Hashes for httptools-0.6.3-cp313-cp313-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6f5aee99ed6451724701bdc7070e60435e808cdb12c16ae1d5ebb2be8e29991 |
|
MD5 | 1518a72550d01bfa6638abb41013b676 |
|
BLAKE2b-256 | 0d15020062f56b064c0c9f94b521d9b37e7a858e6b9e5aa079443f899734ea8a |
Hashes for httptools-0.6.3-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95b2ced1857bf1be81741f7549434dad90b4b29f5e902f0904d251b2393c8f6b |
|
MD5 | 5e3d9e73a8be60fc983253d9d403c7d8 |
|
BLAKE2b-256 | b234a66eafdcae9ad7741865b0995f7dd60691c823c308907caa3cf3e8ea8ebb |
Hashes for httptools-0.6.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c3b7415b830fb603db77d17c32eeee737349f79eb835cd6130ed4410b357ecf |
|
MD5 | c37a58f09f45eb32f67789f9f3bceb0b |
|
BLAKE2b-256 | b92a7a1273b87d028c4819c8e93428ac802ed59183c5df023f2c9af7e929183e |
Hashes for httptools-0.6.3-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9bd2340f1b266735bfdaea3c43106a1c175a15b4f67b8e0953dbbe14fa6c74b |
|
MD5 | d2d09a289c905b7d024dc53d7779a520 |
|
BLAKE2b-256 | 8f49a0e87901c397f1b129b0838ed28242b31bb52a40f5423d4708db244b3589 |
Hashes for httptools-0.6.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 256ea2a9b7eb3d7d63a0c9a3b870ee6559b766d4615a9138e6c9f2fdcc27d22e |
|
MD5 | 1b55969ac439ba489a57c450c9ef351f |
|
BLAKE2b-256 | 88dfd88c95cb7d3fbe8ec9b3908426f63f8035991b90d847d57457cd6ba9fe52 |
Hashes for httptools-0.6.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 887f8a2fc6b2cecc9c5cee24f667b90ec3a9b2cd8937de7d7bb31e14132829ac |
|
MD5 | b2b7ebd754005a6d92391a4cd3d98e37 |
|
BLAKE2b-256 | 1ed666a8b78be167ee64cdcd67a0f0385c47b32b792435f72a3a6bec09da0a58 |
Hashes for httptools-0.6.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbf13d52c9065395d561564b0c535b4d086c8eca19f310458be95ed271189b5 |
|
MD5 | 2352dedc0e268fa8cd32f54a932027e3 |
|
BLAKE2b-256 | 3c13df3336e69b68fa2169cfe00b4a0fd5b27480b1bf3cf6a9a51d65769b5185 |
Hashes for httptools-0.6.3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2263c4183d6529729adb4f91582d47d07efda6393da7ae303c3e81d989b6556 |
|
MD5 | 1d6a989cf6324be993eaf41f0b637980 |
|
BLAKE2b-256 | 98fbe5911b92b59af53f9fe81d7b6a3b9a515ab7654c281227454ce1089dad3e |
Hashes for httptools-0.6.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49b62ec677b6107f41ba6520c7d91436b7a35cc6696c30e67943c0eebef86821 |
|
MD5 | fa67b376e50492d13b92207b9e6373d5 |
|
BLAKE2b-256 | f5c49a3f33140b914caefb64b27276c6742f6f15468d634871a7d31f3551696b |
Hashes for httptools-0.6.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e9bd857018ab2cce2cb581a3ba0e702534fb84c354eac5df2e30a008b3e3ee |
|
MD5 | e3919b2793ce517d65b7e0885eb04a67 |
|
BLAKE2b-256 | a0b7ac31a2a0dc952ee523c6a5072f18386d6dab7787e0589e08dec94caee6b6 |
Hashes for httptools-0.6.3-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 998811136c25b785ca69995d1e62c0a3371e910d85325ac5f9f31b4b52a94f38 |
|
MD5 | bb9bdbb0ff88eea7c1fbd48baf2882fd |
|
BLAKE2b-256 | 8d9bccc596e40b838b698703756d5de48941181793ee330c761d242687230a58 |
Hashes for httptools-0.6.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee5f1f94085eefbc1f18c18d9a90e5983ad3413ccff24897b80b4e4001cf6a3 |
|
MD5 | bd1ce9d302bb732402f288a62869809b |
|
BLAKE2b-256 | 67c16e818fb9de77a12746eb1fb09d37b59f30abd17d726edce17f0972358340 |
Hashes for httptools-0.6.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f326494f2c61f5d6f21354fc9e089551ee6d65f7364e227516e9bad3599f875 |
|
MD5 | 5a87a686af85afd4be3c135488d1aa31 |
|
BLAKE2b-256 | 52ecc86b6185284dce699e3c6fc377acf4f982e8b837b2f4141ba647c8a2e436 |
Hashes for httptools-0.6.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ad32d9b28820a969859681fee34c4ef08d9f14925e27bfa440ead044cfd156 |
|
MD5 | ec90b74ee18011a041f18ce637b3b2a7 |
|
BLAKE2b-256 | b096a365fe9f6ac4246e38cfaddb33caabd81c037ae5da79d4c4ace8368e8412 |
Hashes for httptools-0.6.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1207ffed0b118560aac90c029ed368df7fb0e332f286193b5d6bd41219afb188 |
|
MD5 | 8858c8e9aa6d8b0ffa043bfd97c384a2 |
|
BLAKE2b-256 | 0fc396eaa5058a3cf31922d7d5582ff5b2db99b05356421d65b8defcb759793e |
Hashes for httptools-0.6.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bc4c4258d1641e287c3a0f531816f1e63d7b9e88bdfc797e81ea690178ea7a9 |
|
MD5 | 0e6d4bf93588fd0aa04a4caee5cd9509 |
|
BLAKE2b-256 | b8ac1e74cc2d90676091d8a1f049a8db445b526638b2e7df9ec89fdc63996994 |
Hashes for httptools-0.6.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ef6c9f9d885b2d0ebf65c5abeab315347ad10521ba1078b21618f97ef306b48 |
|
MD5 | e6c8658db9294c10d39cfb3032241071 |
|
BLAKE2b-256 | d8f84aa4486d8aaadb2d3ec33b1347f0fb2b60857cc42e0a196cd3b4f97eb24a |
Hashes for httptools-0.6.3-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e9967aa12ce3ec9125cc60ae8400a65c91e78add3edd4f371b5345a06df45be |
|
MD5 | 827b1cc2e50271e911a2f45332b907e9 |
|
BLAKE2b-256 | b8601091af1fa122f96fe1c709e0286c12c646231380493d42b16befed17cacc |
Hashes for httptools-0.6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7864ff7298c3997148107f65799c7d25f2834e0702d4fed00992e852c47f5ea1 |
|
MD5 | a827340ade8bcb85dc64b3ccbdbd5c2e |
|
BLAKE2b-256 | f3489ed51012a55cc0d207158ead62ae4d19065ad25e0271df65816fd9c19a5f |
Hashes for httptools-0.6.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c402184cc6d218b3c9310a0ce3932b5a17d348c27cd521f5aff86e7800dfab |
|
MD5 | 320882ff40b0aaa36cdd0aaa91234dd6 |
|
BLAKE2b-256 | 0d509fcb7806c40c3e4289e7fb6bf266ed11b4e0ba792a9342215d22f382b0ca |
Hashes for httptools-0.6.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00765b976a601fe827b146df1bed9cdf427491f7a298712365d5798c24fc89c5 |
|
MD5 | 9a5b8c40f0aabd2478c7451498012ede |
|
BLAKE2b-256 | 1adf1b1d247b4c6e029428dd2b11951dda25c22c20a8e7b3293053e488d55e5e |
Hashes for httptools-0.6.3-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e3298343b23c6d4a0c8ee318433d10327773e828247e9032ee05b858d63cb9 |
|
MD5 | 7c4925007f9fd9b503777355968f57de |
|
BLAKE2b-256 | ecc6ab52258632d98bb75e9ac1e201c7e519c5c9cb664fe8636c8ca3038468c7 |
Hashes for httptools-0.6.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a22558c5435d20437fc5de72123d3bd85b5134724e0b484492713a12e1ab8c1f |
|
MD5 | 128a9b5efb3c01f446bab992d4f84e07 |
|
BLAKE2b-256 | af636aba22800c8d16ce20dc6fdebd98b22d346faab2990eed0cfc48a8859a2a |
Hashes for httptools-0.6.3-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05e76fdcec89d44fa5197af767d2d8eacce1bcc3250ab2e6cd90352e51a8f961 |
|
MD5 | e02cdb048a21531c1acaa243c65c63cf |
|
BLAKE2b-256 | 5aefd852db09df291a689a735897ddbfa81bba56213b17e41bd7295e93c1afa2 |
Hashes for httptools-0.6.3-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40f9734ee7422be3359ff40c08dfc5214b50fd76f7f56877ab1c8b89867cbe46 |
|
MD5 | 3c76c363474270cd5af06b6d35a70229 |
|
BLAKE2b-256 | 0fdd66742fdc768d7634939eeafa70c52e25f2b3919497f6c065b9f0710a6902 |
Hashes for httptools-0.6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca7f056cc839f51f2714e31025a19b370fb425a01214aebff04ca7f0fc7564f |
|
MD5 | d414ce249e00ec680f96f5a16fa23e3f |
|
BLAKE2b-256 | 83fbc6689778253f949a8e10e2c9378de6facc8be5576227d2b6b0ac63956616 |
Hashes for httptools-0.6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7847d0692f29306c0483323a96875b3fd10f5725efa085e276f817d843a8766d |
|
MD5 | 19e618bfc24853d07ec3561edb1e7848 |
|
BLAKE2b-256 | 9560f9e06812706da70b896d4602be80ab7d7be45f9525c2a1d67e2e99b10bcb |
Hashes for httptools-0.6.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c55999b7394341600896e4781e2c261814982c6c090b3485feb747ce0798bb |
|
MD5 | 2a7a34dc48ea04a5f81f54af94d32bba |
|
BLAKE2b-256 | 53fa1746494d03550a231c4a1e9e3bfb43f41b8e49eb4e9acc646fe4ee11136a |
Hashes for httptools-0.6.3-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eb428c7490f8fb167eac57e704ae16780ebb88bfff00452273a419c9895a98a |
|
MD5 | fe7be6bdb54bef11f0fe35fb603bfa5c |
|
BLAKE2b-256 | 2e5702034e88a06a4ceb5557fd336dc740f80a41eae34f806e64fa620b16163b |
Hashes for httptools-0.6.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8657856f77a7f1d6a8d98a39d9b09f8b5719b99c6c8f7ed5b05dcae810c07c7a |
|
MD5 | 7edad58722f7689bd66efc62560bb1bf |
|
BLAKE2b-256 | ae76f030bf3d948a3f7f1d8bdf57782c25c9a004423d6b2cea36a5976cbe69bc |
Hashes for httptools-0.6.3-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634e2c772125067299556e0cda0d930d84652b8d3afbdf74643d03fedab88c64 |
|
MD5 | 15d245223e4b74f4ca155d36ee5eafbe |
|
BLAKE2b-256 | e8c118b9df7396ff3488bf7e6f910be7096a6821de8de4f6a1d46ca08d062ce3 |
Hashes for httptools-0.6.3-cp38-cp38-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 338ce7fa2230d0ff0303da6aa006b83b0939b2feb168c571f383cf33b6304ff6 |
|
MD5 | 9c2f684fe2cbd304cee697ac26824b5c |
|
BLAKE2b-256 | 994fbcdeea42a6c2f1f1670d7cb3ec314937b833b5eb0ec703548fb2d61d9c92 |
Hashes for httptools-0.6.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc34d088c6652606b9952886724e390f2af1d3e723f094246ce5c8a270def580 |
|
MD5 | 59a252ebf4a9421faef428af3027e98b |
|
BLAKE2b-256 | ed5530e24296b119e7e027f383980015ddbf9be72eb65ac11fb1bd520bccd842 |
Hashes for httptools-0.6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24893be8cd6a635b305e40c417938d9e2afecff7581cff6f725322b9449ee539 |
|
MD5 | 113a7e7eb3da7f330cb0318fd3abfef8 |
|
BLAKE2b-256 | 1cddd9a41f29b197b852a334f128c0ad976599ff68995192d75f606d6fba472a |
Hashes for httptools-0.6.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e39b0ade6d46d328228d3759e766fab14cc6c7ac7f2013736f0037009754271 |
|
MD5 | b73a7ff3387408b9e6d85ef9f6650d1e |
|
BLAKE2b-256 | af7fa49a54a7f5b57485fffa57b8c53cafca1c20eccccc76d5149655bb4b35cc |
Hashes for httptools-0.6.3-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4315cbfcb0c77691436484b76561633e7474b831fa6c0334ebaf80fd20bc781e |
|
MD5 | f2163bf94461aae90d6592570ee4e83b |
|
BLAKE2b-256 | f7ab89a176d0b7d2cc38995525ca7cb1c252618d3ccf7d1ae49a406d3fdc932c |