Parsing headers from string or dictionary
Project description
parserheader
Parsing headers from string or dictionary
Installing
Install and update using pip
:
$ pip install parserheader
parserheader supports Python 2 and newer, Python 3 and newer, and PyPy.
Example
What does it look like? Here is an example of a simple parserheader program:
import parserheader
...
def setHeaders():
ph = parserheader.parserheader()
header_str = """
POST /upload/ HTTP/1.1
Host: google.com.com
Connection: keep-alive
Content-Length: 1220
Cache-Control: max-age=0
Origin: http://www.google.com.com
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Referer: http://www.google.com/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,id;q=0.8
Cookie: PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9
"""
headers = ph.parserHeader(header_str)
print("headers =", headers)
return headers
setHeaders()
And what it looks like when run:
$ python test.py
headers = {'Origin': 'http://www.google.com', 'Content-Length': '1220', 'Accept-Language': 'en-US,en;q=0.9,id;q=0.8', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'Host': 'google.com', 'Referer': 'http://www.google.com/', 'Cache-Control': 'max-age=0', 'Cookie': 'PHPSESSID=41a0f0ac4545d3f5ba9a4ba415b777e9', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded'}
Support
- Python 2.7 +, Python 3.x
- Windows, Linux
Links
- License:
MIT <https://github.com/cumulus13/parserheader/src/default/LICENSE.rst>
_ - Code: https://github.com/cumulus13/parserheader
- Issue tracker: https://github.com/cumulus13/parserheader/issues
Author
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
parserheader-0.37.tar.gz
(7.4 kB
view details)
Built Distribution
File details
Details for the file parserheader-0.37.tar.gz
.
File metadata
- Download URL: parserheader-0.37.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 799d6081c97a2c6dd25641c140f0282054ad5cb92f6fe5eaf78ce6532c9f7727 |
|
MD5 | d12df2c0dc0d692e4676e70c9cfcfb72 |
|
BLAKE2b-256 | c003f0b5fd44df00372bab453fcc509c1e55a01fab3c592f221ad93589d232d1 |
File details
Details for the file parserheader-0.37-py2.py3-none-any.whl
.
File metadata
- Download URL: parserheader-0.37-py2.py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8acbdc85795b27471f215690abb2ce23535a3256f9ac0ec2d213b5b1bb6c32d6 |
|
MD5 | 0522e8f78ecce7ed058083e7e9d60b55 |
|
BLAKE2b-256 | 956d33e251c3a0c69d3cb84dbca338aafe1d7ccdcb65fdac1f28e49dce7bd6be |