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
and a function for parsing URLs
httptools.parse_url
. 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
httptools-0.1.1.tar.gz
(106.2 kB
view hashes)
Built Distributions
Close
Hashes for httptools-0.1.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a4b1b2012b28e68306575ad14ad5e9120b34fccd02a81eb08838d7e3bbb48be |
|
MD5 | b1481f82be4b84376b8e23bb399cde00 |
|
BLAKE2b-256 | abfd4e0e917ac490e3c122ee416eb44a33598982fd36f0d6162a4a3b740288eb |
Close
Hashes for httptools-0.1.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3592e854424ec94bd17dc3e0c96a64e459ec4147e6d53c0a42d0ebcef9cb9c5d |
|
MD5 | c3d65d257a302e81098234f039d68d10 |
|
BLAKE2b-256 | ff0b6a581de6d1dccbec5688ae023c6e3840a4684542a0931d6519a17e07d2cd |
Close
Hashes for httptools-0.1.1-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fea04e126014169384dee76a153d4573d90d0cbd1d12185da089f73c78390437 |
|
MD5 | f02a7c6de616a9c23095e121ac4f4aa9 |
|
BLAKE2b-256 | c0f014d8b4d68f46c652cc03f5f04f0a1e9f8178a255f89001370419a57f90aa |
Close
Hashes for httptools-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96eb359252aeed57ea5c7b3d79839aaa0382c9d3149f7d24dd7172b1bcecb009 |
|
MD5 | 456f7c1bd85308ca0585bf8ba2022384 |
|
BLAKE2b-256 | aefb9a5313e73071eecb0043cb99035647fb0f5f19dd7719abe39da159e39f41 |
Close
Hashes for httptools-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56b6393c6ac7abe632f2294da53f30d279130a92e8ae39d8d14ee2e1b05ad1f2 |
|
MD5 | ebf09627e56e9efc5de73cc587ed396d |
|
BLAKE2b-256 | 4452295101ea5a60f9bee805a3ca422863600ba5cac4e2778ac7bd56efab1231 |
Close
Hashes for httptools-0.1.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96da81e1992be8ac2fd5597bf0283d832287e20cb3cfde8996d2b00356d4e17f |
|
MD5 | f0a95b9938a324b3e13575b46eec475e |
|
BLAKE2b-256 | f9346d6a8979de9d5f343c4de244bf5c5bfa8a9bcc5e0e6e3607388c0bfd7d67 |
Close
Hashes for httptools-0.1.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac0aa11e99454b6a66989aa2d44bca41d4e0f968e395a0a8f164b401fefe359a |
|
MD5 | 11c9c4a921daaac051f15debeea49058 |
|
BLAKE2b-256 | 93d9a1650d7c401ba7b3d54690e01776acb152a15b3a0daeeb43c4bb844bef12 |
Close
Hashes for httptools-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc3114b9edbca5a1eb7ae7db698c669eb53eb8afbbebdde116c174925260849c |
|
MD5 | 611803b4a4842c041d47ccbf8b0a494c |
|
BLAKE2b-256 | b1a6dc1e7e8f4049ab70d52c9690ec10652e268ab2542853033cc1d539594102 |
Close
Hashes for httptools-0.1.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c6acd66765a934e8730bf0e9dfaac6fdcf2a4334212bd4a0a1c78f16475ca6 |
|
MD5 | 6d1974cb8c36fe4ceb7d69f020bc6065 |
|
BLAKE2b-256 | 17b95ec14289fc7a31c6778722f3a3f1b070eebfbe246fc21c532ff1ac130b0f |
Close
Hashes for httptools-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa3cd71e31436911a44620473e873a256851e1f53dee56669dae403ba41756a4 |
|
MD5 | c0b1fdfa2ad2c7123e32a3e8830ef1a4 |
|
BLAKE2b-256 | 18af57f793f9646c882511c582d1c776dea9c3f11b9478bc3ca4777af211c22b |
Close
Hashes for httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2719e1d7a84bb131c4f1e0cb79705034b48de6ae486eb5297a139d6a3296dce |
|
MD5 | 0beedb9d7c22af5124c83d1d487977df |
|
BLAKE2b-256 | 3216f36bf4435ad8c8b664c32f4d131d5fa6472eceea213e967ebb14af7903d9 |