Skip to main content

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 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.

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

httplint-2023.10.3.tar.gz (66.9 kB view details)

Uploaded Source

Built Distribution

httplint-2023.10.3-py3-none-any.whl (99.1 kB view details)

Uploaded Python 3

File details

Details for the file httplint-2023.10.3.tar.gz.

File metadata

  • Download URL: httplint-2023.10.3.tar.gz
  • Upload date:
  • Size: 66.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for httplint-2023.10.3.tar.gz
Algorithm Hash digest
SHA256 a4d541e8785521abe0e81c7d57d0e0e742111c409de416f019b6a6595d8768a6
MD5 139751cae2096adf1f99bf3b0486e0d1
BLAKE2b-256 5fee4dd1d0dbd54f3a4cb6d7d096f150656e3b6c4fd1c2c37ed89220033d323e

See more details on using hashes here.

Provenance

File details

Details for the file httplint-2023.10.3-py3-none-any.whl.

File metadata

  • Download URL: httplint-2023.10.3-py3-none-any.whl
  • Upload date:
  • Size: 99.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for httplint-2023.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6c4583e2000259100550d7ecb93acb8192482a1cefa5ff950b7cf18ae0a36a8d
MD5 aa23a14816433b161d99d7b922185014
BLAKE2b-256 64fe29452f0fc88d9eb1e306c08e5619bb0998dabb16e0ec26e5651a1be4cbb5

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page