Skip to main content

A collection of framework independent HTTP protocol utils.

Project description

Tests

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

  1. Clone this repository with git clone --recursive git@github.com:MagicStack/httptools.git

  2. Create a virtual environment with Python 3.5: python3.5 -m venv envname

  3. Activate the environment with source envname/bin/activate

  4. Install Cython with pip install cython

  5. Run make and make test.

License

MIT.

Project details


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 details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

httptools-0.1.2-cp39-cp39-win_amd64.whl (96.2 kB view details)

Uploaded CPython 3.9Windows x86-64

httptools-0.1.2-cp39-cp39-manylinux1_x86_64.whl (219.2 kB view details)

Uploaded CPython 3.9

httptools-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl (101.2 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

httptools-0.1.2-cp38-cp38-win_amd64.whl (96.1 kB view details)

Uploaded CPython 3.8Windows x86-64

httptools-0.1.2-cp38-cp38-manylinux1_x86_64.whl (229.6 kB view details)

Uploaded CPython 3.8

httptools-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl (100.4 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

httptools-0.1.2-cp37-cp37m-win_amd64.whl (94.7 kB view details)

Uploaded CPython 3.7mWindows x86-64

httptools-0.1.2-cp37-cp37m-manylinux1_x86_64.whl (219.8 kB view details)

Uploaded CPython 3.7m

httptools-0.1.2-cp37-cp37m-macosx_10_14_x86_64.whl (99.1 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

httptools-0.1.2-cp36-cp36m-win_amd64.whl (94.3 kB view details)

Uploaded CPython 3.6mWindows x86-64

httptools-0.1.2-cp36-cp36m-manylinux1_x86_64.whl (218.7 kB view details)

Uploaded CPython 3.6m

httptools-0.1.2-cp36-cp36m-macosx_10_14_x86_64.whl (100.0 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

httptools-0.1.2-cp35-cp35m-manylinux1_x86_64.whl (214.8 kB view details)

Uploaded CPython 3.5m

httptools-0.1.2-cp35-cp35m-macosx_10_14_x86_64.whl (98.4 kB view details)

Uploaded CPython 3.5mmacOS 10.14+ x86-64

File details

Details for the file httptools-0.1.2.tar.gz.

File metadata

  • Download URL: httptools-0.1.2.tar.gz
  • Upload date:
  • Size: 106.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2.tar.gz
Algorithm Hash digest
SHA256 07659649fe6b3948b6490825f89abe5eb1cec79ebfaaa0b4bf30f3f33f3c2ba8
MD5 dc705e023679bdeb76cebb478d82dfe7
BLAKE2b-256 8b354fd5fa3d0c670dbccc38b7b8b98354155c47e1871309147ff654ae071a1f

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 96.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9abd788465aa46a0f288bd3a99e53edd184177d6379e2098fd6097bb359ad9d6
MD5 2d63588c54fdcadef3b786375923d37b
BLAKE2b-256 d5b01aa5e1c6a00e4e64a39d81b9ec7696cbdebce522ddfcc7ecf2730e0df7a9

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 219.2 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 31629e1f1b89959f8c0927bad12184dc07977dcf71e24f4772934aa490aa199b
MD5 8496e856382c806c5bd1fa3299412e88
BLAKE2b-256 d660ea7ed827eda212f916a2bc2b944150b4f0448f74694c6f3a636032edcb9b

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 101.2 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 851026bd63ec0af7e7592890d97d15c92b62d9e17094353f19a52c8e2b33710a
MD5 4db000d65204c620fd2becd77fe19e54
BLAKE2b-256 d263b958dd563ba427c442603882e3261dc23b637b48506daa647b488e6abb46

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 96.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bda99a5723e7eab355ce57435c70853fc137a65aebf2f1cd4d15d96e2956da7b
MD5 25e5cbd735c1a22cadc86acedf610605
BLAKE2b-256 ed407a5471f834cb4e258446c514fb9b311f2c17cbaf9eb185f79928a1fdef91

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 229.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fb7199b8fb0c50a22e77260bb59017e0c075fa80cb03bb2c8692de76e7bb7fe7
MD5 66f2ccf018687a63c3685e1ab3bf4053
BLAKE2b-256 5843ba2b7fde6d1397a2da08f2c057ee746aac149e7e9f6da534d22aaac90fd1

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 100.4 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c1c63d860749841024951b0a78e4dec6f543d23751ef061d6ab60064c7b8b524
MD5 66070ac3be6d34f0c6d9835c03c6c184
BLAKE2b-256 245007c90d73c1da18b2d8d545b1e247a08f7d6d4810a6cf24738d013ff4b5fb

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 94.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fbf7ecd31c39728f251b1c095fd27c84e4d21f60a1d079a0333472ff3ae59d34
MD5 b86c31097ff3c1451c5f39e4ebdffb55
BLAKE2b-256 76a3b5567b0b1c0671d720f5bad1e5874225d9b8f34ab67e0a6054b17c7916da

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 219.8 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aebdf0bd7bf7c90ae6b3be458692bf6e9e5b610b501f9f74c7979015a51db4c4
MD5 275d6152e6d07131a71d387b7bddb77e
BLAKE2b-256 252e485131e3aa113929b425f83854fafc190aa7df716cbeb258c875752f0c6e

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 99.1 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 8fcca4b7efe353b13a24017211334c57d055a6e132c7adffed13a10d28efca57
MD5 6becf500497732e3439b677bf20f67a2
BLAKE2b-256 e08e57ef6e951497ebd7055beddfb453fec5df404c8690b274b4c230aa3d4c6f

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 94.3 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 08b79e09114e6ab5c3dbf560bba2cb2257ea38cdaeaf99b7cb80d8f92622fcd9
MD5 019ff7260f858c8ab2491690d36fcf79
BLAKE2b-256 e5437816354c5ad62d29993cb92eb65afecf9d9e66a3ecb7d8666ee93c726d56

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 218.7 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f759717ca1b2ef498c67ba4169c2b33eecf943a89f5329abcff8b89d153eb500
MD5 a2dd12d876d5d87ca5fa1d78ef4ac2ef
BLAKE2b-256 47e200aebb83e78e2e3b0d4373c1819f74d09d28b468c886ef53a75efc812eb3

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 100.0 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 dce59ee45dd6ee6c434346a5ac527c44014326f560866b4b2f414a692ee1aca8
MD5 91772625e99c4d58a496a3849473a966
BLAKE2b-256 12e032bacfa5563b2419b8fe6daca528f81c04e94bc7ebb9b0399f8467f56476

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 214.8 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c4111a0a8a00eff1e495d43ea5230aaf64968a48ddba8ea2d5f982efae827404
MD5 12b2f63789ca7ef6d525db4be87b193e
BLAKE2b-256 3d0e3d9d6032525720d8d6ce4d526b99aacaf55951ce578341faa13447c57ddc

See more details on using hashes here.

File details

Details for the file httptools-0.1.2-cp35-cp35m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.2-cp35-cp35m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 98.4 kB
  • Tags: CPython 3.5m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for httptools-0.1.2-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1e35aa179b67086cc600a984924a88589b90793c9c1b260152ca4908786e09df
MD5 5cbbe48a58a5f527c7eb932bb67da2d3
BLAKE2b-256 17592518b47cedd6428aebabe5c0387436a95f4eeb2a1178c1eabffad57465bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page