circuits.web.http – HTTP Protocol — circuits 2.1.0 documentation

# circuits 2.1.0 documentation

# `circuits.web.http` – HTTP Protocol

Hyper Text Transfer Protocol

This module implements the server side Hyper Text Transfer Protocol or commonly known as HTTP.

## Components

class `circuits.web.http.` `HTTP`(encoding='utf-8', channel='web')

  Bases: `circuits.core.components.BaseComponent`

  HTTP Protocol Component

  Implements the HTTP server protocol and parses and processes incoming HTTP messages, creating and sending an appropriate response.

  The component handles `Read` events on its channel and collects the associated data until a complete HTTP request has been received. It parses the request’s content and puts it in a `Request` object and creates a corresponding `Response` object. Then it emits a `Request` event with these objects as arguments.

  The component defines several handlers that send a response back to the client.

  `_on_response`(response)

    `Response` Event Handler

    Parameters: | response (`Response`) – the `Response` object created when the HTTP request was initially received.

    This handler builds an HTTP response data stream from the information contained in the response object and sends it to the client (firing `Write` events).

  `_on_read`(sock, data)

    Read Event Handler

    Process any incoming data appending it to an internal buffer. Split the buffer by the standard HTTP delimiter CRLF and create Raw Event per line. Any unfinished lines of text, leave in the buffer.

  `_on_httperror`(event, request, response, code, **kwargs)

    Default HTTP Error Handler

    Default Error Handler that by default just fires a `Response` event with the response as argument. The response is normally modified by a `HTTPError` instance or a subclass thereof.

  `_on_request_success`(e, value)

    Handler for the `RequestSuccess` event that is automatically generated after all handlers for a `Request` event have been invoked successfully.

    Parameters: | e – the successfully handled `Request` event (having as attributes the associated `Request` and `Response` objects). value – the value(s) returned by the invoked handler(s).

    This handler converts the value(s) returned by the (successfully invoked) handlers for the initial `Request` event to a body and assigns it to the `Response` object’s `body` attribute. It then fires a `Response` event with the `Response` object as argument.

## Events

See `circuits.web.events.Request` in circuits.web.events – Events.

## Functions

none