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 --branch <Branch/Tag>
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: {}".format(RequestParser.request_method))
print("- request_path: {}".format(RequestParser.request_path))
print("- request_pathParams: {}".format(RequestParser.request_pathParams.dumps(indent=4)))
print("- request_queryParams: {}".format(RequestParser.request_queryParams.dumps(indent=4)))
print("- request_fragment: {}".format(RequestParser.request_fragment))
print("- request_httpVersion: {}".format(RequestParser.request_httpVersion))
print("- request_headers: {}".format(RequestParser.request_headers.dumps(indent=4)))
print("- request_body: {}".format(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_httpVersion: {}".format(ResponseParser.response_httpVersion))
print("- response_statusCode: {}".format(ResponseParser.response_statusCode))
print("- response_statusText: {}".format(ResponseParser.response_statusText))
print("- response_headers: {}".format(ResponseParser.response_headers.dumps(indent=4)))
print("- response_body: {}".format(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
File details
Details for the file TP-HTTP-Request-Response-Parser-2024.2.5.tar.gz
.
File metadata
- Download URL: TP-HTTP-Request-Response-Parser-2024.2.5.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3218b0b7b3ae1ac69f6b8b4965495498acc7a25751336291223505f7b629f8e |
|
MD5 | 1a1bf33e4a59ecbcf9f1f7e1f194a3c6 |
|
BLAKE2b-256 | e5020227cf88057388a77eba2743f6abef1ef2f5abc36295da1a6b3c20f802c2 |
File details
Details for the file TP_HTTP_Request_Response_Parser-2024.2.5-py3-none-any.whl
.
File metadata
- Download URL: TP_HTTP_Request_Response_Parser-2024.2.5-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b6c8c501b31f14c9fd1b1f54327306e857b610d743930a005e6f53c70879e9 |
|
MD5 | 0ba2b2e4fcdda672cf1744f7ef2492a8 |
|
BLAKE2b-256 | c9df44505007cdeefa5dfd3e06b9495fba9378ec2fb925d1745dc732edc49809 |
File details
Details for the file TP_HTTP_Request_Response_Parser-2024.2.5-py2-none-any.whl
.
File metadata
- Download URL: TP_HTTP_Request_Response_Parser-2024.2.5-py2-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05282cde72939a8270e9bc0003ab24f0b83f1f8263cb98aa0ddb9cec3ca61d72 |
|
MD5 | f1e3ca49ce2708e1aeb86b849111d9dd |
|
BLAKE2b-256 | caebaf4b09cc52377c37e888d3b2b18e777349c05d0c6afc6047d31794295f4a |