Lint for HTTP messages.
Project description
httplint
This Python library lints HTTP messages; it checks them for correctness and reports any issues it finds.
It has been extracted from REDbot, which will eventually depend upon it. Unlike REDbot, it does not perform any 'active' checks by making requests to the network, and it does not have a Web user interface.
Using httplint
httplint exposes two classes for linting: HttpRequestLinter and HttpResponseLinter. They expose the following methods for telling the linter about the HTTP message:
- As appropriate:
process_request_topline, which takes threebytesarguments:method,uri, andversionprocess_response_topline, which takes threebytesarguments:version,status_code, andstatus_phrase
process_headersfor the headers, taking a list of (name,value) tuples (bothbytes)feed_contentfor the body (which can be called zero to many times), taking aninbytesargumentfinish_contentwhen done, which has two arguments; aboolindicating whether the response was complete, and an optional list of tuples for the trailers, in the same format thatprocess_headerstakes.
For example:
from httplint import HttpResponseLinter
linter = HttpResponseLinter()
linter.process_response_topline(b'HTTP/1.1', b'200', b'OK')
linter.process_headers([
(b'Content-Type', b'text/plain'),
(b'Content-Length', b'10'),
(b'Cache-Control', b'max-age=60')
])
linter.feed_content(b'12345')
linter.feed_content(b'67890')
linter.finish_content(True)
Interpreting Notes
Once a message has been linted, the results will appear on the notes property. This is a list of Note objects, each having the following attributes:
category- the Note's category; seenote.categorieslevel- seenote.levelssummary- a brief, one-line description of the notedetail- a longer explanation
Note that summary is textual, and needs to be escaped in a markup environment; detail, however, is already escaped HTML.
Continuing our example:
for note in linter.notes:
print(note.summary)
and the output should be:
The Content-Length header is correct.
This response allows all caches to store it.
This response doesn't have a Date header.
This response is fresh until 1 min from now.
This response may still be served by a cache once it becomes stale.
Field Descriptions
The description of any field can be found by calling get_field_description. For example:
>>> from httplint import get_field_description
>>> get_field_description("Allow")
'The `Allow` response header advertises the set of methods that are supported by the resource.'
If a description cannot be found it will return None.
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file httplint-2023.12.1.tar.gz.
File metadata
- Download URL: httplint-2023.12.1.tar.gz
- Upload date:
- Size: 69.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
037f81575456be804adc230c90e6b0630d958cf6f3fbe079526daa3a241d0752
|
|
| MD5 |
170481e2ef24a2fdf8cd39ece4686701
|
|
| BLAKE2b-256 |
2813a1a541fcaa7e0486013e5ae2a488ae7a550848b513e92de6e94cf8f187fe
|
File details
Details for the file httplint-2023.12.1-py3-none-any.whl.
File metadata
- Download URL: httplint-2023.12.1-py3-none-any.whl
- Upload date:
- Size: 102.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e82249993155519b3e54c632f9c54fc52f11b021d92bee90fddbbd709c3af6
|
|
| MD5 |
d50811d0e7d699fed048be6507a20a76
|
|
| BLAKE2b-256 |
772f21cee707261eb712d59596e426031576d6caf3aa0896a52d6a1778faf4b6
|