Skip to content

ercpe/httpheader

 
 

Repository files navigation

httpheader

Httpheader is a Python module for dealing with HTTP headers and content negotiation. It provides a set of utility functions and classes which properly implement all the details and edge cases of the HTTP 1.1 protocol headers. Httpheader is intended to be used as part of a larger web framework or any application that must deal with HTTP.

In particular, httpheader can handle:

  • Byte range requests (multipart/byteranges)
  • Content negotiation (content type, language, all the Accept-* style headers; including full support for priority/qvalue handling.
  • Content/media type parameters
  • Conversion to and from HTTP date and time formats

Summary of functions

There are a few classes defined by this module:

  • class content_type -- media types such as 'text/plain'
  • class language_tag -- language tags such as 'en-US'
  • class range_set -- a collection of (byte) range specifiers
  • class range_spec -- a single (byte) range specifier

The primary functions in this module may be categorized as follows:

  • Content negotiation functions...

    • acceptable_content_type()
    • acceptable_language()
    • acceptable_charset()
    • acceptable_encoding()
  • Mid-level header parsing functions...

    • parse_accept_header()
    • parse_accept_language_header()
    • parse_range_header()
  • Date and time...

    • http_datetime()
    • parse_http_datetime()
  • Utility functions...

    • quote_string()
    • remove_comments()
    • canonical_charset()
  • Low level string parsing functions...

    • parse_comma_list()
    • parse_comment()
    • parse_qvalue_accept_list()
    • parse_media_type()
    • parse_number()
    • parse_parameter_list()
    • parse_quoted_string()
    • parse_range_set()
    • parse_range_spec()
    • parse_token()
    • parse_token_or_quoted_string()

And there are some specialized exception classes:

  • RangeUnsatisfiableError
  • RangeUnmergableError
  • ParseError

See also

More information

Complete documentation and additional information is available on the httpheader project homepage.

This module is also registered on the Python Package Index (PyPI) as package "httpheader". This should make it easy to install into most Python environments.

About

Python module for parsing HTTP headers: Accept with qvalues, byte ranges, etc.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.6%
  • Makefile 0.4%