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.1.tar.gz (106.2 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.1-cp38-cp38-win_amd64.whl (97.1 kB view details)

Uploaded CPython 3.8Windows x86-64

httptools-0.1.1-cp38-cp38-manylinux1_x86_64.whl (227.6 kB view details)

Uploaded CPython 3.8

httptools-0.1.1-cp38-cp38-macosx_10_13_x86_64.whl (102.8 kB view details)

Uploaded CPython 3.8macOS 10.13+ x86-64

httptools-0.1.1-cp37-cp37m-win_amd64.whl (95.7 kB view details)

Uploaded CPython 3.7mWindows x86-64

httptools-0.1.1-cp37-cp37m-manylinux1_x86_64.whl (217.5 kB view details)

Uploaded CPython 3.7m

httptools-0.1.1-cp37-cp37m-macosx_10_13_x86_64.whl (101.4 kB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

httptools-0.1.1-cp36-cp36m-win_amd64.whl (95.7 kB view details)

Uploaded CPython 3.6mWindows x86-64

httptools-0.1.1-cp36-cp36m-manylinux1_x86_64.whl (216.5 kB view details)

Uploaded CPython 3.6m

httptools-0.1.1-cp36-cp36m-macosx_10_13_x86_64.whl (102.3 kB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

httptools-0.1.1-cp35-cp35m-manylinux1_x86_64.whl (212.6 kB view details)

Uploaded CPython 3.5m

httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl (100.8 kB view details)

Uploaded CPython 3.5mmacOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: httptools-0.1.1.tar.gz
  • Upload date:
  • Size: 106.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 41b573cf33f64a8f8f3400d0a7faf48e1888582b6f6e02b82b9bd4f0bf7497ce
MD5 063a9b6f8c79cf5f11592e7a49715275
BLAKE2b-256 d96faad92c3f090e2f74dd728d58d3bba4c832d35199814af99673ee7300b582

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 97.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0a4b1b2012b28e68306575ad14ad5e9120b34fccd02a81eb08838d7e3bbb48be
MD5 b1481f82be4b84376b8e23bb399cde00
BLAKE2b-256 abfd4e0e917ac490e3c122ee416eb44a33598982fd36f0d6162a4a3b740288eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 227.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3592e854424ec94bd17dc3e0c96a64e459ec4147e6d53c0a42d0ebcef9cb9c5d
MD5 c3d65d257a302e81098234f039d68d10
BLAKE2b-256 ff0b6a581de6d1dccbec5688ae023c6e3840a4684542a0931d6519a17e07d2cd

See more details on using hashes here.

File details

Details for the file httptools-0.1.1-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.1-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 102.8 kB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 fea04e126014169384dee76a153d4573d90d0cbd1d12185da089f73c78390437
MD5 f02a7c6de616a9c23095e121ac4f4aa9
BLAKE2b-256 c0f014d8b4d68f46c652cc03f5f04f0a1e9f8178a255f89001370419a57f90aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 96eb359252aeed57ea5c7b3d79839aaa0382c9d3149f7d24dd7172b1bcecb009
MD5 456f7c1bd85308ca0585bf8ba2022384
BLAKE2b-256 aefb9a5313e73071eecb0043cb99035647fb0f5f19dd7719abe39da159e39f41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 217.5 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 56b6393c6ac7abe632f2294da53f30d279130a92e8ae39d8d14ee2e1b05ad1f2
MD5 ebf09627e56e9efc5de73cc587ed396d
BLAKE2b-256 4452295101ea5a60f9bee805a3ca422863600ba5cac4e2778ac7bd56efab1231

See more details on using hashes here.

File details

Details for the file httptools-0.1.1-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.1-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 101.4 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 96da81e1992be8ac2fd5597bf0283d832287e20cb3cfde8996d2b00356d4e17f
MD5 f0a95b9938a324b3e13575b46eec475e
BLAKE2b-256 f9346d6a8979de9d5f343c4de244bf5c5bfa8a9bcc5e0e6e3607388c0bfd7d67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ac0aa11e99454b6a66989aa2d44bca41d4e0f968e395a0a8f164b401fefe359a
MD5 11c9c4a921daaac051f15debeea49058
BLAKE2b-256 93d9a1650d7c401ba7b3d54690e01776acb152a15b3a0daeeb43c4bb844bef12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 216.5 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bc3114b9edbca5a1eb7ae7db698c669eb53eb8afbbebdde116c174925260849c
MD5 611803b4a4842c041d47ccbf8b0a494c
BLAKE2b-256 b1a6dc1e7e8f4049ab70d52c9690ec10652e268ab2542853033cc1d539594102

See more details on using hashes here.

File details

Details for the file httptools-0.1.1-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.1-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 102.3 kB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 86c6acd66765a934e8730bf0e9dfaac6fdcf2a4334212bd4a0a1c78f16475ca6
MD5 6d1974cb8c36fe4ceb7d69f020bc6065
BLAKE2b-256 17b95ec14289fc7a31c6778722f3a3f1b070eebfbe246fc21c532ff1ac130b0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httptools-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 212.6 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fa3cd71e31436911a44620473e873a256851e1f53dee56669dae403ba41756a4
MD5 c0b1fdfa2ad2c7123e32a3e8830ef1a4
BLAKE2b-256 18af57f793f9646c882511c582d1c776dea9c3f11b9478bc3ca4777af211c22b

See more details on using hashes here.

File details

Details for the file httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 100.8 kB
  • Tags: CPython 3.5m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a2719e1d7a84bb131c4f1e0cb79705034b48de6ae486eb5297a139d6a3296dce
MD5 0beedb9d7c22af5124c83d1d487977df
BLAKE2b-256 3216f36bf4435ad8c8b664c32f4d131d5fa6472eceea213e967ebb14af7903d9

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