Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TP-HTTP-Request-Response-Parser-2023.11.26.tar.gz (5.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file TP-HTTP-Request-Response-Parser-2023.11.26.tar.gz.

File metadata

File hashes

Hashes for TP-HTTP-Request-Response-Parser-2023.11.26.tar.gz
Algorithm Hash digest
SHA256 12ff0ce9c6faf5a84206c0e59bc90a88de3cf6657ddc7b3c5188d1356f4366df
MD5 54b2aa706173726d582637c23a5cdc93
BLAKE2b-256 bbed6c23e9c66edb31396c8dea35e8a5d9f6863d75de671fc3f1cc54adcfc181

See more details on using hashes here.

File details

Details for the file TP_HTTP_Request_Response_Parser-2023.11.26-py3-none-any.whl.

File metadata

File hashes

Hashes for TP_HTTP_Request_Response_Parser-2023.11.26-py3-none-any.whl
Algorithm Hash digest
SHA256 751033097eaaf36e2e9230dbcd3c39a409cd0865a438bdf3990b72418783adac
MD5 e1eb5c3f807c3514a7b664b8a27617a5
BLAKE2b-256 ab93e6f605b58ed5776a08eedd12cb7257bea57bfc38903d3340d9205c3f98da

See more details on using hashes here.

File details

Details for the file TP_HTTP_Request_Response_Parser-2023.11.26-py2-none-any.whl.

File metadata

File hashes

Hashes for TP_HTTP_Request_Response_Parser-2023.11.26-py2-none-any.whl
Algorithm Hash digest
SHA256 32bf9f59e5448b2b5cb23941c6b048bd6327d9c07fe409c4c1a5e307d70fb113
MD5 a0095decbc3122fb311afa98960dbe28
BLAKE2b-256 48d5a2321cff2b21a4d5f6542901913d501d84f9bc2875642ed26b9434e5847d

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