https://github.com/adriangb/httparse
Python wrapper for Rust's httparse HTTP parser
https://github.com/adriangb/httparse
Last synced: 3 months ago
JSON representation
Python wrapper for Rust's httparse HTTP parser
- Host: GitHub
- URL: https://github.com/adriangb/httparse
- Owner: adriangb
- License: mit
- Created: 2022-11-06T00:18:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-14T05:22:06.000Z (over 2 years ago)
- Last Synced: 2024-04-24T16:46:27.427Z (about 1 year ago)
- Language: Rust
- Size: 37.1 KB
- Stars: 40
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# httparse

Python wrapper for Rust's [httparse](https://github.com/seanmonstar/httparse).
See this project on [GitHub](https://github.com/adriangb/httparse).## Example
```python
from httparse import RequestParserparser = RequestParser()
buff = b"GET /index.html HTTP/1.1\r\nHost"
parsed = parser.parse(buff)
assert parsed is None# a partial request, so we try again once we have more data
buff = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n"
parsed = parser.parse(buff)
assert parsed is not None
assert parsed.method == "GET"
assert parsed.path == "/index.html"
assert parsed.version == 1
assert parsed.body_start_offset == len(buff)
headers = [(h.name.encode(), h.value) for h in parsed.headers]
assert headers == [(b"Host", b"example.domain")]
```