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.2.tar.gz
(106.7 kB
view hashes)
Built Distributions
Close
Hashes for httptools-0.1.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9abd788465aa46a0f288bd3a99e53edd184177d6379e2098fd6097bb359ad9d6 |
|
MD5 | 2d63588c54fdcadef3b786375923d37b |
|
BLAKE2b-256 | d5b01aa5e1c6a00e4e64a39d81b9ec7696cbdebce522ddfcc7ecf2730e0df7a9 |
Close
Hashes for httptools-0.1.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31629e1f1b89959f8c0927bad12184dc07977dcf71e24f4772934aa490aa199b |
|
MD5 | 8496e856382c806c5bd1fa3299412e88 |
|
BLAKE2b-256 | d660ea7ed827eda212f916a2bc2b944150b4f0448f74694c6f3a636032edcb9b |
Close
Hashes for httptools-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 851026bd63ec0af7e7592890d97d15c92b62d9e17094353f19a52c8e2b33710a |
|
MD5 | 4db000d65204c620fd2becd77fe19e54 |
|
BLAKE2b-256 | d263b958dd563ba427c442603882e3261dc23b637b48506daa647b488e6abb46 |
Close
Hashes for httptools-0.1.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bda99a5723e7eab355ce57435c70853fc137a65aebf2f1cd4d15d96e2956da7b |
|
MD5 | 25e5cbd735c1a22cadc86acedf610605 |
|
BLAKE2b-256 | ed407a5471f834cb4e258446c514fb9b311f2c17cbaf9eb185f79928a1fdef91 |
Close
Hashes for httptools-0.1.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7199b8fb0c50a22e77260bb59017e0c075fa80cb03bb2c8692de76e7bb7fe7 |
|
MD5 | 66f2ccf018687a63c3685e1ab3bf4053 |
|
BLAKE2b-256 | 5843ba2b7fde6d1397a2da08f2c057ee746aac149e7e9f6da534d22aaac90fd1 |
Close
Hashes for httptools-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c63d860749841024951b0a78e4dec6f543d23751ef061d6ab60064c7b8b524 |
|
MD5 | 66070ac3be6d34f0c6d9835c03c6c184 |
|
BLAKE2b-256 | 245007c90d73c1da18b2d8d545b1e247a08f7d6d4810a6cf24738d013ff4b5fb |
Close
Hashes for httptools-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbf7ecd31c39728f251b1c095fd27c84e4d21f60a1d079a0333472ff3ae59d34 |
|
MD5 | b86c31097ff3c1451c5f39e4ebdffb55 |
|
BLAKE2b-256 | 76a3b5567b0b1c0671d720f5bad1e5874225d9b8f34ab67e0a6054b17c7916da |
Close
Hashes for httptools-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aebdf0bd7bf7c90ae6b3be458692bf6e9e5b610b501f9f74c7979015a51db4c4 |
|
MD5 | 275d6152e6d07131a71d387b7bddb77e |
|
BLAKE2b-256 | 252e485131e3aa113929b425f83854fafc190aa7df716cbeb258c875752f0c6e |
Close
Hashes for httptools-0.1.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fcca4b7efe353b13a24017211334c57d055a6e132c7adffed13a10d28efca57 |
|
MD5 | 6becf500497732e3439b677bf20f67a2 |
|
BLAKE2b-256 | e08e57ef6e951497ebd7055beddfb453fec5df404c8690b274b4c230aa3d4c6f |
Close
Hashes for httptools-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b79e09114e6ab5c3dbf560bba2cb2257ea38cdaeaf99b7cb80d8f92622fcd9 |
|
MD5 | 019ff7260f858c8ab2491690d36fcf79 |
|
BLAKE2b-256 | e5437816354c5ad62d29993cb92eb65afecf9d9e66a3ecb7d8666ee93c726d56 |
Close
Hashes for httptools-0.1.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f759717ca1b2ef498c67ba4169c2b33eecf943a89f5329abcff8b89d153eb500 |
|
MD5 | a2dd12d876d5d87ca5fa1d78ef4ac2ef |
|
BLAKE2b-256 | 47e200aebb83e78e2e3b0d4373c1819f74d09d28b468c886ef53a75efc812eb3 |
Close
Hashes for httptools-0.1.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce59ee45dd6ee6c434346a5ac527c44014326f560866b4b2f414a692ee1aca8 |
|
MD5 | 91772625e99c4d58a496a3849473a966 |
|
BLAKE2b-256 | 12e032bacfa5563b2419b8fe6daca528f81c04e94bc7ebb9b0399f8467f56476 |
Close
Hashes for httptools-0.1.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4111a0a8a00eff1e495d43ea5230aaf64968a48ddba8ea2d5f982efae827404 |
|
MD5 | 12b2f63789ca7ef6d525db4be87b193e |
|
BLAKE2b-256 | 3d0e3d9d6032525720d8d6ce4d526b99aacaf55951ce578341faa13447c57ddc |
Close
Hashes for httptools-0.1.2-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e35aa179b67086cc600a984924a88589b90793c9c1b260152ca4908786e09df |
|
MD5 | 5cbbe48a58a5f527c7eb932bb67da2d3 |
|
BLAKE2b-256 | 17592518b47cedd6428aebabe5c0387436a95f4eeb2a1178c1eabffad57465bb |