httpq#

from httpq import Request, Response, state

httpq implementation.


class Headers[source]#

Container for HTTP headers.

property raw#

The raw headers.

Return type:

bytes


class Message[source]#
__init__(protocol, headers, body)[source]#

Initializes an HTTP message.

Parameters:
  • protocol (Union[bytes, str, int, bool, None, Item]) – The protocol of the HTTP message.

  • headers (Union[Headers, dict]) – The headers of the HTTP message.

  • body (Union[bytes, str, int, bool, None, Item]) – The body of the HTTP message.

Note

Message is the base class for Request and Response, and is not intended to be used directly.

feed(msg)[source]#

Adds chuncks of the message to the internal buffer.

Parameters:

msg (bytes) – The message to add to the internal buffer.

Return type:

state

classmethod parse(msg)[source]#

Parses a complete HTTP message.

Parameters:

msg (bytes) – The message to parse.

Return type:

Message

property raw#

Returns the raw (bytes) HTTP message.

Return type:

bytes


class Request[source]#
__init__(method, target, protocol, headers, body)[source]#

Initializes an HTTP request.

Parameters:
  • method (Union[bytes, str, int, bool, None, Item]) – The method of the HTTP request.

  • target (Union[bytes, str, int, bool, None, Item]) – The target of the HTTP request.

  • protocol (Union[bytes, str, int, bool, None, Item]) – The protocol of the HTTP request.

  • headers (Union[Headers, dict]) – The headers of the HTTP request.

  • body (Union[bytes, str, int, bool, None, Item]) – The body of the HTTP request.

class Response[source]#
__init__(protocol, status, reason, headers, body)[source]#

Initializes an HTTP response.

Parameters:
  • protocol (Union[bytes, str, int, bool, None, Item]) – The protocol of the HTTP response.

  • status (Union[bytes, str, int, bool, None, Item]) – The status of the HTTP response.

  • reason (Union[bytes, str, int, bool, None, Item]) – The reason of the HTTP response.

  • headers (Union[Headers, dict]) – The headers of the HTTP response.

  • body (Union[bytes, str, int, bool, None, Item]) – The body of the HTTP response.


class state(value)[source]#

States of the HTTP request.

  • TOP: Message is at the top line.

  • HEADERS: Message is in the headers.

  • BODY: Message is in the body.