pycohttpparser Python API

This page documents pycohttpparser’s Python API.

An important feature to note is that, wherever possible, pycohttpparser uses memoryview objects to avoid copying data. The only objects that are not returned as ``memoryview``s are response status codes and the HTTP minor version number.

class pycohttpparser.api.Parser[source]

A single HTTP parser object. This object can parse HTTP requests and responses using picohttpparser.

This object is not thread-safe, and it does maintain state that is shared across parsing requests. For this reason, make sure that access to this object is synchronized if you use it across multiple threads.

parse_request(buffer)[source]

Parses a single HTTP request from a buffer.

Parameters:buffer – A memoryview object wrapping a buffer containing a HTTP request.
Returns:A Request object, or None if there is not enough data in the buffer.
parse_response(buffer)[source]

Parses a single HTTP response from a buffer.

Parameters:buffer – A memoryview object wrapping a buffer containing a HTTP response.
Returns:A Response object, or None if there is not enough data in the buffer.
class pycohttpparser.api.Request

Request(method, path, minor_version, headers, consumed)

consumed

Alias for field number 4

count(value) → integer -- return number of occurrences of value
headers

Alias for field number 3

index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

method

Alias for field number 0

minor_version

Alias for field number 2

path

Alias for field number 1

class pycohttpparser.api.Response

Response(status, msg, minor_version, headers, consumed)

consumed

Alias for field number 4

count(value) → integer -- return number of occurrences of value
headers

Alias for field number 3

index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

minor_version

Alias for field number 2

msg

Alias for field number 1

status

Alias for field number 0

class pycohttpparser.api.ParseError[source]

An invalid HTTP message was passed to the parser.