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 performs all message-level checks for REDbot, but does not perform any 'active' checks by making requests to the network, and it does not have a Web user interface.

Using httplint as a Library

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)

Using httplint from the Command Line

httplint can also be used from the command line. For example:

> curl -s -i --raw https://www.mnot.net/ | httplint -n
* The Content-Length header is correct.
* The resource last changed 8 days 6 hr ago.
* This response allows all caches to store it.
* The server's clock is correct.
* This response is fresh until 3 hr from now.
* This response may still be served by a cache once it becomes stale.

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httplint-2024.4.1.tar.gz (70.6 kB view details)

Uploaded Source

Built Distribution

httplint-2024.4.1-py3-none-any.whl (104.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: httplint-2024.4.1.tar.gz
  • Upload date:
  • Size: 70.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for httplint-2024.4.1.tar.gz
Algorithm Hash digest
SHA256 6e18db2c85af0e77b15ede922980ee8e7cc482ea60efec76f99725f7a5d5c782
MD5 50ab12e3fd427ffdc89e376c50215adf
BLAKE2b-256 adb97870e155060f0c256ae700be5213bbcc880a27518030c055b09a4bf355d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httplint-2024.4.1-py3-none-any.whl
  • Upload date:
  • Size: 104.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for httplint-2024.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afe7050a2ed65c8e443d6bcde272701969a88a59d0a3c2b216c885efecf62d41
MD5 e6c311645f45e3c635f2316e1fccc23c
BLAKE2b-256 e5767d1b8136235a263b592a82d7f8af9e7e2c8d249bf92e6a17fdc4376c5be7

See more details on using hashes here.

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