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 (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

  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.2.0.tar.gz (169.3 kB view details)

Uploaded Source

Built Distributions

httptools-0.2.0-cp39-cp39-win_amd64.whl (141.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

httptools-0.2.0-cp39-cp39-manylinux1_x86_64.whl (343.2 kB view details)

Uploaded CPython 3.9

httptools-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl (156.2 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

httptools-0.2.0-cp38-cp38-win_amd64.whl (141.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

httptools-0.2.0-cp38-cp38-manylinux1_x86_64.whl (354.8 kB view details)

Uploaded CPython 3.8

httptools-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl (155.5 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

httptools-0.2.0-cp37-cp37m-win_amd64.whl (139.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

httptools-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (344.6 kB view details)

Uploaded CPython 3.7m

httptools-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl (154.1 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

httptools-0.2.0-cp36-cp36m-win_amd64.whl (139.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

httptools-0.2.0-cp36-cp36m-manylinux1_x86_64.whl (343.6 kB view details)

Uploaded CPython 3.6m

httptools-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl (154.8 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

httptools-0.2.0-cp35-cp35m-manylinux1_x86_64.whl (339.2 kB view details)

Uploaded CPython 3.5m

httptools-0.2.0-cp35-cp35m-macosx_10_14_x86_64.whl (153.0 kB view details)

Uploaded CPython 3.5m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: httptools-0.2.0.tar.gz
  • Upload date:
  • Size: 169.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 94505026be56652d7a530ab03d89474dc6021019d6b8682281977163b3471ea0
MD5 195862c50a0e583ff80df307c9e4ec55
BLAKE2b-256 968208c5ee0191ea7f765e9a44cc66827c0ba35b896f72b4d31f9cd9d180b08f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 141.3 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.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 200fc1cdf733a9ff554c0bb97a4047785cfaad9875307d6087001db3eb2b417f
MD5 910f1dcc62b1e6fba9633d08dab4bd56
BLAKE2b-256 d4cbc15e64f204d748533c197434afa325e48766b7045de2e4b15af198ba2338

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 343.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.2.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fd3b8905e21431ad306eeaf56644a68fdd621bf8f3097eff54d0f6bdf7262065
MD5 ad01ca04a19495a6009971849479f046
BLAKE2b-256 100a95cacee1b444993a1c2106b4fdb890ea3a648918f7cb8744a6cd1f9591db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 156.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.2.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b08d00d889a118f68f37f3c43e359aab24ee29eb2e3fe96d64c6a2ba8b9d6557
MD5 b7bf1cac361d4b8caef8ed01853126e1
BLAKE2b-256 564724d1d1116ff514ecaf1f4e6f832856375df567d59191acb593ac8f818c48

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 141.2 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.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cc9be041e428c10f8b6ab358c6b393648f9457094e1dcc11b4906026d43cd380
MD5 5b5acef91f9c6ef855db6936b2149044
BLAKE2b-256 2a4285763f28626b613b470442987eccd461f3308485b1d9c528499d683b2979

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 354.8 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.2.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 813871f961edea6cb2fe312f2d9b27d12a51ba92545380126f80d0de1917ea15
MD5 ac524aa01cca3c1709f9794c4d3d2f6a
BLAKE2b-256 b3e7b893f9e994732e8763d8f59913cb70faaa44f41df2fa15fa1624827d8f2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 155.5 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.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a289c27ccae399a70eacf32df9a44059ca2ba4ac444604b00a19a6c1f0809943
MD5 0636a9f912c438ae94900a07562a62aa
BLAKE2b-256 03d15d617f1ca8d7839963db6c30e47f5c2276a99c44ee2c2535dcbe1ffcde4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 139.8 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.2.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d5682eeb10cca0606c4a8286a3391d4c3c5a36f0c448e71b8bd05be4e1694bfb
MD5 3f15ef1fa8f6da71fbaa97a5ba40874a
BLAKE2b-256 415a89c0f669ae9a58e6855590a0f5c0af0f37a6bea57b51b0f79b6911c0dfcb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 344.6 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.2.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 80ffa04fe8c8dfacf6e4cef8277347d35b0442c581f5814f3b0cf41b65c43c6e
MD5 766a3db72733f5180e0290f7a7906bda
BLAKE2b-256 4c87ebb92639705924aac5ed6aa91bd4332b20d7180f3e94bd168742e7671025

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 154.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.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 01b392a166adcc8bc2f526a939a8aabf89fe079243e1543fd0e7dc1b58d737cb
MD5 29771b47404238c14239d2db4139673a
BLAKE2b-256 d20517556eb2088d280cd3fe78e52e334cf24d052cdb27102e87eee5233fef80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 139.5 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.2.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a7594f9a010cdf1e16a58b3bf26c9da39bbf663e3b8d46d39176999d71816658
MD5 ed2f3861ec804c5a357fa534edc7d003
BLAKE2b-256 9489e88f473d8b9b0e60c9e3693fe16e4c8ef8aec67f4228e1a65e8dc6c2eb97

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 343.6 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.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3ab1f390d8867f74b3b5ee2a7ecc9b8d7f53750bd45714bf1cb72a953d7dfa77
MD5 267546f16d5e2b4e7b877b5a6f809bc0
BLAKE2b-256 818fa8238a287d1bd3455e4297a358d4cdbd1da2bfb0ec3fbfb8a254119aa8e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 154.8 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.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a23166e5ae2775709cf4f7ad4c2048755ebfb272767d244e1a96d55ac775cca7
MD5 dd9396cc77fc101789d969f1aa7136d4
BLAKE2b-256 25d0092d6d1541a37885dbf11525ca9ad2a7082714511256801961d495b529c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 339.2 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.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 78d03dd39b09c99ec917d50189e6743adbfd18c15d5944392d2eabda688bf149
MD5 b5c2743c8c2dd94a45db6a1fdc5c5ce2
BLAKE2b-256 aea50b450216fe120f2f92996e4c7632d8db65d1fdc574c98cfb7adb6148cc1e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.2.0-cp35-cp35m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 153.0 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.2.0-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 79dbc21f3612a78b28384e989b21872e2e3cf3968532601544696e4ed0007ce5
MD5 54a91aa1e43886dff205c92988951ec7
BLAKE2b-256 8e4c4d22571b5f8eba7eff92c09e46b0d360f7813c3408bc68fcdbd60d1b6e6d

See more details on using hashes here.

Supported by

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