Skip to main content

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 three bytes arguments: method, uri, and version
    • process_response_topline, which takes three bytes arguments: version, status_code, and status_phrase
  • process_headers for the headers, taking a list of (name, value) tuples (both bytes)
  • feed_content for the body (which can be called zero to many times), taking an inbytes argument
  • finish_content when done, which has two arguments; a bool indicating whether the response was complete, and an optional list of tuples for the trailers, in the same format that process_headers takes.

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; see note.categories
  • level - see note.levels
  • summary - a brief, one-line description of the note
  • detail - 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.

Metadata

Release files for httplint 2023.10.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for httplint 2023.10.2
File Size Uploaded
httplint-2023.10.2.tar.gz 66.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for httplint 2023.10.2
File Interpreter ABI Platform
httplint-2023.10.2-py3-none-any.whl Python 3 none any Details

Total release size: 166.1 kB

Release files / httplint-2023.10.2.tar.gz

Download URL httplint-2023.10.2.tar.gz
Size 66.9 kB
Tags Source
SHA-256 checksum
How to use checksums
539e1ac28fe61134d2c087cc5f75c8d136e550e3e722e02bf2bbeb4c421d632c
BLAKE2b-256 checksum
How to use checksums
b8ded5ac4a48665d1f8dc0567a7f8d484cc9b64b2246c59fcfa00667c42ff450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / httplint-2023.10.2-py3-none-any.whl

Download URL httplint-2023.10.2-py3-none-any.whl
Size 99.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e17fc36655b8ece5655059dd3d6a31175e8d6e1e475e2b3898d880289a4610ea
BLAKE2b-256 checksum
How to use checksums
38f3ae6d5d01fff1381f9f220a36537daaf7e57e590a76777bced1447dccad7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

2023.10.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page