You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
request_parser is an HTTP request parsing library in Python providing an easy API to access information in HTTP requests.
Getting Started
Dependencies
Requires six and future. These can be installed as below.
pip install six
pip install future
Example
To use the library, git clone the repository and copy the library directory request_parser to a location that is present in PYTHONPATH or copy somewhere and add that location to PYTHONPATH.
Once the library is setup, it can be used as shown below.
fromrequest_parser.http.requestimportHttpRequestfromioimportBytesIOdefparse_request_example(request=None):
ifrequestisNone:
return# create an iterable object out of request bytesrequest_stream=BytesIO(request)
# create an HttpRequest object for the requesthttp_request=HttpRequest(request_stream=request_stream)
# parse request headerhttp_request.parse_request_header()
# parse request bodyhttp_request.parse_request_body()
# do stuff with parsed information from the HttpRequest objectprint"This is a request to: "+http_request.get_host()
It is also possible to use the parse() method of HttpRequest object to parse the request header and the body in a single call.
Following picture shows how the infromation contained in an HttpRequest object looks like after successfully parsing a multipart/form-data request.