Collection of tools to parse, manipulate, and compile raw HTTP messages.
Project description
🧳 httpsuite
httpsuite
is a collection of tools to parse, manipulate, and compile raw HTTP messages. Built to be used as a dependency for larger projects that require parsing, modifying, requesting, and responding to raw HTTP requests.
Installing
To install just httpsuite
:
pip install httpsuite
This package is depedent on toolbox
. If you plan to contribute make sure to install the dev
requirements:
pip install httpsuite[dev]
Documentation
Read the documentation here.
Use
httpsuite
provides two main objects, Request
and Response
. Both objects can be initialized with either __init__
or parse
:
from httpsuite import Request, Response
import json
request = Request(
method="GET",
target="/",
protocol="HTTP/1.1",
headers={"Host": "www.google.com", "Connection": "keep-alive", "Content-Length": "18"},
body=json.dumps({"hello": "world"}),
)
response = Response(
protocol="HTTP/1.1",
status=200,
status_msg="OK",
headers={"Host": "www.google.com", "Connection": "keep-alive", "Content-Length": "18"},
body=json.dumps({"hello": "world"}),
)
or
from httpsuite import Request, Response
request = Request.parse(
(
b"GET / HTTP/1.1\r\n"
b"Host: www.google.com\r\n"
b"Connection: keep-alive\r\n"
b"Content-Length: 18\r\n"
b"\r\n"
b'{"hello": "world"}'
)
)
response = Response.parse(
(
b"HTTP/1.1 200 OK\r\n"
b"Host: www.google.com\r\n"
b"Connection: keep-alive\r\n"
b"Content-Length: 18\r\n"
b"\r\n"
b'{"hello": "world"}'
)
)
Request
and Responses
objects can be directly modified as one would expect, with no limitations as to the type:
request.method = "POST"
request.headers += {"Accept": "*/*"}
response.status = 100
response.status_msg = b"Continue"
Internally, every item of a request or response is saved as an Item
, a special object type that allows easy setting and comparisons on the fly:
response.status == 100 # >>> True
response.status == "100" # >>> True
response.status == b"100" # >>> True
Once the object is modified to the users preference, utilizing the Request
and Response
object is as easy as calling a property (specifically .raw
):
print(request.raw)
# >>> b'POST / HTTP/1.1\r\nHost: www.google.com\r\nConnection: keep-alive\r\nContent-Length: 18\r\nAccept: */*\r\n\r\n{"hello": "world"}'
print(response.raw)
# >>> b'HTTP/1.1 100 Continue\r\nHost: www.google.com\r\nConnection: keep-alive\r\nContent-Length: 18\r\n\r\n{"hello": "world"}'
Uniquely, the __str__
method for Request
and Response
return the objects with arrows to make obvious of its type:
print(request)
print(response)
→ POST / HTTP/1.1
→ Host: www.google.com
→ Connection: keep-alive
→ Content-Length: 18
→ Accept: */*
→
→ {"hello": "world"}
← HTTP/1.1 100 Continue
← Host: www.google.com
← Connection: keep-alive
← Content-Length: 18
←
← {"hello": "world"}
For more information and examples of httpsuite
, check out the docs.
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
Built Distribution
File details
Details for the file httpsuite-1.2.0.tar.gz
.
File metadata
- Download URL: httpsuite-1.2.0.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71e2de2c3dabdfa0fc44daf0a1b8cdcf6832dfe15ab6056e32c7273a5cb682d9 |
|
MD5 | e01da0343c7d3ba608fb01be0cdaf1e6 |
|
BLAKE2b-256 | 4a58df115413672d344f2646effde6b109167a37acb31d17a0420058c3ed4cfa |
File details
Details for the file httpsuite-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: httpsuite-1.2.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e1ed6e12dfeb164aea3965ca881b06e182f2ba5d7179227f0e5ba80ef94a5b6 |
|
MD5 | 3e7dc89b6d88afa639deb0b45a26b272 |
|
BLAKE2b-256 | 1df70a9d39e9a8d0ed27d75dbe2877b0c0879bda596234ac987e65fab2e89b82 |