Parse the raw HTTP Request/ Response to the Object
Project description
TP-HTTP-Request-Response-Parser
Parse the raw HTTP Request/ Response to the Object
Installation
From PyPI:
pip install TP-HTTP-Request-Response-Parser
From Source:
git clone https://github.com/truocphan/TP-HTTP-Request-Response-Parser.git
cd TP-HTTP-Request-Response-Parser
python setup.py build
python setup.py install
Basic Usage
from TP_HTTP_Request_Response_Parser import *
# Parsing HTTP Request
rawRequest = """GET /v1/promo/extension HTTP/2
Host: d2y7f743exec8w.cloudfront.net
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en-US;q=0.9,en;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.97 Safari/537.36
Connection: close
Cache-Control: max-age=0
"""
# RequestParser = TP_HTTP_REQUEST_PARSER(open("request.txt", "rb").read().decode("utf-8"))
RequestParser = TP_HTTP_REQUEST_PARSER(rawRequest, ordered_dict=True)
print("- request_method:", RequestParser.request_method)
print("- request_path:", RequestParser.request_path)
print("- request_query:", RequestParser.request_query.dumps(indent=4))
print("- request_fragment:", RequestParser.request_fragment)
print("- request_headers:", RequestParser.request_headers.dumps(indent=4))
print("- request_body:", RequestParser.request_body.dumps(indent=4))
# Parsing HTTP Response
rawResponse = """HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
Server: nginx
Date: Mon, 21 Aug 2023 03:55:08 GMT
Etag: W/"846e0a9b390c273d2d7a6843085411d1"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 06024e22-f233-4517-b0f6-f444c8464e7b
Strict-Transport-Security: max-age=63072000; includeSubDomains
Strict-Transport-Security: max-age=63072000; preload
Vary: Accept-Encoding,Accept
X-Cache: Miss from cloudfront
Via: 1.1 19175f36fb9c16ba394561bae28598da.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: SGN50-P2
X-Amz-Cf-Id: eKssgTNGDCswPiQtSYFD1MRNBJCTHEbnQp4MQjtQx2B4eM7oqXYIHg==
{"ok":true,"promo":[]}"""
# ResponseParser = TP_HTTP_RESPONSE_PARSER(open("response.txt", "rb").read().decode("utf-8"))
ResponseParser = TP_HTTP_RESPONSE_PARSER(rawResponse, ordered_dict=True)
print("- response_statusCode:", ResponseParser.response_statusCode)
print("- response_statusText:", ResponseParser.response_statusText)
print("- response_headers:", ResponseParser.response_headers.dumps(indent=4))
print("- response_body:", ResponseParser.response_body.dumps(indent=4))
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
Built Distributions
Close
Hashes for TP-HTTP-Request-Response-Parser-2023.12.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | df502e533c494b918d69a7ac3e2b3b78a8bb60543feabffd6873c6a65f9ab1d1 |
|
MD5 | 7e05fb757eeb4a211d50ca35fe14e3f6 |
|
BLAKE2b-256 | ecb7a1864cb87a29e6870d094b6b93d6a4a8c42856e3896ba229c961bce14093 |
Close
Hashes for TP_HTTP_Request_Response_Parser-2023.12.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a11eac308d1962429ca8cbc37ac7d87a06d5f2c5ce787dd94a3d11961e9e678 |
|
MD5 | 41ec52798cb1daa85867bb4b5c734cc3 |
|
BLAKE2b-256 | ad5bf74d1507dc024ff844fd26d6e0f5804ae50d8cbdc57fabda1706bd9d5e32 |
Close
Hashes for TP_HTTP_Request_Response_Parser-2023.12.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df8a2e9418cef1f6dccea42dcd7e447a7f0fdaf8018576156e9507ac536731c6 |
|
MD5 | 0b1d48f273d98590c6b240f0d0af385d |
|
BLAKE2b-256 | 9abafb8565d1231c604cda039b4254c4076dcdcc3ecd24f25475b5a445d1c978 |