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.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f3cafedd6aa20ae05f81f2e616ea6f92116c8a0f8dcb79dc798df3356836e2 |
|
MD5 | a1e3845f2d4915b19f486f70809b0b75 |
|
BLAKE2b-256 | 80e6158e8d56f6b4d29295cfa244f1e79a65d0987bb3941d36863e7f6e06e3b6 |
Hashes for httptools-0.6.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e22896b42b95b3237eccc42278cd72c0df6f23247d886b7ded3163452481e38 |
|
MD5 | 545b12e27aa9f0716f6c836b5cbb6f9f |
|
BLAKE2b-256 | 62c7eca648bc8eb24caf5e1614e80d3a189187eec3ce50c6f4dda545398eb267 |
Hashes for httptools-0.6.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f959e4770b3fc8ee4dbc3578fd910fab9003e093f20ac8c621452c4d62e517cb |
|
MD5 | a80a4d416db2ef021d4f83ef701b7248 |
|
BLAKE2b-256 | dcba97266d7c207fb6572bb8ec4154849812b26169442e17aae0e58cc7ceb7fb |
Hashes for httptools-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 259920bbae18740a40236807915def554132ad70af5067e562f4660b62c59b90 |
|
MD5 | 52a3e40f699ae4e08d83e90364d8a049 |
|
BLAKE2b-256 | 5e62d7620a822006cb61506ed730cf622c0678cb89fa03372820e9d328cd4a67 |
Hashes for httptools-0.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03bfd2ae8a2d532952ac54445a2fb2504c804135ed28b53fefaf03d3a93eb1fd |
|
MD5 | 61bca453092ea5dfedf4848311229117 |
|
BLAKE2b-256 | 8aa64ee791339f70776a0d57bd066f3721a24491a8b4b4faf572036d163296d1 |
Hashes for httptools-0.6.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 274bf20eeb41b0956e34f6a81f84d26ed57c84dd9253f13dcb7174b27ccd8aaf |
|
MD5 | c2629a844fbf9edda6fcd397fec9c1d9 |
|
BLAKE2b-256 | 6146c06a1f2a35d961204c1fd38700220df71ddcf5d01ff0f4cae73e28b67480 |
Hashes for httptools-0.6.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 721e503245d591527cddd0f6fd771d156c509e831caa7a57929b55ac91ee2b51 |
|
MD5 | 930c148b64cbda948d6fed48a3d6f7cf |
|
BLAKE2b-256 | 85df63720eadbadca00b7f91bc724972ca3a946670598354bef1de779c7c62e2 |
Hashes for httptools-0.6.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0781fedc610293a2716bc7fa142d4c85e6776bc59d617a807ff91246a95dea35 |
|
MD5 | 24bae8b7a13b273735f1ce412b11f625 |
|
BLAKE2b-256 | d563f1594d00b4ef9c137edc0ff202d84e684b6989f9b8b4d1475098ca320c9d |
Hashes for httptools-0.6.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82f228b88b0e8c6099a9c4757ce9fdbb8b45548074f8d0b1f0fc071e35655d1c |
|
MD5 | 5bb54b47d9eb75e5e114e71f79605f59 |
|
BLAKE2b-256 | ef8900b9805ac1205572afa4f2042542365b8cecf53ffddd1df635fcdde6fa0d |
Hashes for httptools-0.6.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463c3bc5ef64b9cf091be9ac0e0556199503f6e80456b790a917774a616aff6e |
|
MD5 | 7a0b8be9664dd5423a15b88fcb311e66 |
|
BLAKE2b-256 | c5faaced15396316b401e74b587610b503ce2b0613b027188f1456bca164ce94 |
Hashes for httptools-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33eb1d4e609c835966e969a31b1dedf5ba16b38cab356c2ce4f3e33ffa94cad3 |
|
MD5 | fdc74f927127fe893ef0012b65b3e806 |
|
BLAKE2b-256 | 730f2a76cef72e35b0696bf61d2458eaff3b5c1ac728e9090b6a87045d65e1c9 |
Hashes for httptools-0.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bdc6675ec6cb79d27e0575750ac6e2b47032742e24eed011b8db73f2da9ed40 |
|
MD5 | 5084c1357018755572af33811c0a8a19 |
|
BLAKE2b-256 | cf09b17fbf88d5c285e7cd8162539ba6f95c778dcd47e44240aa14afd0982bb8 |
Hashes for httptools-0.6.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72205730bf1be875003692ca54a4a7c35fac77b4746008966061d9d41a61b0f5 |
|
MD5 | 287b4c8cba70d773cfa6e670c5b1b815 |
|
BLAKE2b-256 | 369c8f237d959e047b1c6d00131c063ce7c5ca48a64fd9b845c94bcb56c9d98c |
Hashes for httptools-0.6.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 818325afee467d483bfab1647a72054246d29f9053fd17cc4b86cda09cc60339 |
|
MD5 | 1a55d44e12cb79b3e1f225f88452431b |
|
BLAKE2b-256 | 8f71d535e9f6967958d21b8fe1baeb7efb6304b86e8fcff44d0bda8690e0aec9 |
Hashes for httptools-0.6.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23b09537086a5a611fad5696fc8963d67c7e7f98cb329d38ee114d588b0b74cd |
|
MD5 | 8b6651ca05588fd816a36a668a0e6913 |
|
BLAKE2b-256 | 2b15a48d8036bf6ed80201f41479df1813ad1e01b48284281edcbefd05c3a364 |
Hashes for httptools-0.6.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea66d94e5a3f68c5e9d86e0894653b87d952e624845e0b0e3ad1c733c6cc75d |
|
MD5 | 2c19bc098a07f29c80b69ac274ed0d13 |
|
BLAKE2b-256 | bf511e2f9691821f715ac63b9c8f6592a36c9025d09bf0ecf19832290480ee8e |
Hashes for httptools-0.6.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a816bb425c116a160fbc6f34cece097fd22ece15059d68932af686520966bd |
|
MD5 | d34deca1eaa14da5ae392ffbb4d5e1b6 |
|
BLAKE2b-256 | 83e05c87bf475dd666bed3e8a949cb2f098b296a74bc534cd6882098aeb0d41c |
Hashes for httptools-0.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b703d15dbe082cc23266bf5d9448e764c7cb3fcfe7cb358d79d3fd8248673ef9 |
|
MD5 | 35304ac75257b37fdec3d63c1a5e3721 |
|
BLAKE2b-256 | 307c9821f018649fb3d175df0293adea3b9158edb75c1328853448f02d52323d |
Hashes for httptools-0.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82c723ed5982f8ead00f8e7605c53e55ffe47c47465d878305ebe0082b6a1755 |
|
MD5 | 561e7f87d5fbe762540af7570dcf528d |
|
BLAKE2b-256 | 287c5ddc99737fb141bd9077f45af23e9d3c83496b4c04bf463e4e72f57043cd |
Hashes for httptools-0.6.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72ec7c70bd9f95ef1083d14a755f321d181f046ca685b6358676737a5fecd26a |
|
MD5 | b7f1025f21ee7af279975c0bcb8b2f57 |
|
BLAKE2b-256 | 1b51ad5ec00731c00a4679ac2d8aaaf439579974fec969d52ec0300a9ec821e2 |
Hashes for httptools-0.6.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f96d2a351b5625a9fd9133c95744e8ca06f7a4f8f0b8231e4bbaae2c485046a |
|
MD5 | 673b67f33688b40d500d99c11af0a119 |
|
BLAKE2b-256 | 2719b13b3815aa50cffcbd00f9505d35e435781cdcecebd7cd4242b0f5b4f544 |
Hashes for httptools-0.6.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22c01fcd53648162730a71c42842f73b50f989daae36534c818b3f5050b54589 |
|
MD5 | 8889f648c5690dea08b20d6c0e9f4888 |
|
BLAKE2b-256 | ef3fdc03c90b23107ff68c3b8a48008a6f0bc07628bee900f187356a57c0dbe6 |
Hashes for httptools-0.6.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73e9d66a5a28b2d5d9fbd9e197a31edd02be310186db423b28e6052472dc8201 |
|
MD5 | c6cc4f9b573142122918dc1b2878665f |
|
BLAKE2b-256 | 0f4026a5bd40bf12c40345fe7eb123e0077162f8896ee079af153b3ffe909285 |
Hashes for httptools-0.6.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93f89975465133619aea8b1952bc6fa0e6bad22a447c6d982fc338fbb4c89649 |
|
MD5 | d096048ed05e657adf202ed2682ddd68 |
|
BLAKE2b-256 | 4e4d21f6a90385a54a05dcda1ca61835bed2aad3dd9003d71ed34265a2a1284c |
Hashes for httptools-0.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d0b0571806a5168013b8c3d180d9f9d6997365a4212cb18ea20df18b938aa0b |
|
MD5 | 9ae0250ebcbea070b92b60d0d5a2bef2 |
|
BLAKE2b-256 | 519d638ce3ce7ef549f6bb6b2b89369b278e8fd4b47cbebc1bf028e1a68608ac |
Hashes for httptools-0.6.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb4a608c631f7dcbdf986f40af7a030521a10ba6bc3d36b28c1dc9e9035a3c0 |
|
MD5 | 2eb7f10948863769b3d0d5a89a73d4f8 |
|
BLAKE2b-256 | 2425f6d51f2f464411eb103e56caeec0d215efb4cddd95f87d708c6def7aa848 |
Hashes for httptools-0.6.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dcc14c090ab57b35908d4a4585ec5c0715439df07be2913405991dbb37e049d |
|
MD5 | df2d605fc1962053a148195ded1b5124 |
|
BLAKE2b-256 | a0353861af367612c20b74862d474c495c2818037287118ed0d3e598cf48439a |
Hashes for httptools-0.6.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf8169e839a0d740f3d3c9c4fa630ac1a5aaf81641a34575ca6773ed7ce041a1 |
|
MD5 | f5beef31b6bfc1e8d752805b41b216fd |
|
BLAKE2b-256 | 456ce5e256103be70d24319f43266be83d1d8c9bfce39c806602601b0635845e |
Hashes for httptools-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e748fc0d5c4a629988ef50ac1aef99dfb5e8996583a73a717fc2cac4ab89932 |
|
MD5 | 181301e25d72acdd61e6c45ea7396c88 |
|
BLAKE2b-256 | 27c158ad85d57a528bff8edd8b9004deadaded11b1195c58b79a39f600c05377 |
Hashes for httptools-0.6.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e41ccac9e77cd045f3e4ee0fc62cbf3d54d7d4b375431eb855561f26ee7a9ec4 |
|
MD5 | 5f71ec90299c16480324fad01907c1d8 |
|
BLAKE2b-256 | ddd779d8374e5aebd87c630b349313771fc1b24bf377af7e429b12c17979690b |
Hashes for httptools-0.6.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26326e0a8fe56829f3af483200d914a7cd16d8d398d14e36888b56de30bec81a |
|
MD5 | 07115ca90108c58cbe1d28e993a6fdc5 |
|
BLAKE2b-256 | 2534787a9035536f00641e41c9aaead1477d1538c18a8606aa61c9edca7f136c |
Hashes for httptools-0.6.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35a541579bed0270d1ac10245a3e71e5beeb1903b5fbbc8d8b4d4e728d48ff1d |
|
MD5 | b17b3d62ef6b905c72e1bb9e22401c5c |
|
BLAKE2b-256 | 263d7d236d77a8ff9306137df7aa3bc6a79c8c53f78f13fb8ad9626a9be1aec2 |
Hashes for httptools-0.6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d802e7b2538a9756df5acc062300c160907b02e15ed15ba035b02bce43e89c |
|
MD5 | d1114e0178136ae1244356e6d52fbb4c |
|
BLAKE2b-256 | ae73eae64945f3bc9d25a57cb1bc35e8fdf2247a9fd027b1749855aeedcb0bcb |
Hashes for httptools-0.6.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47043a6e0ea753f006a9d0dd076a8f8c99bc0ecae86a0888448eb3076c43d717 |
|
MD5 | cf7882a9e4534666ee52009087282d46 |
|
BLAKE2b-256 | 93ebdfa4990960c1c3a75d2b5a75e44f358a94530a988e2380ebc29782166fe5 |