httpserver package

Submodules

httpserver.httpserver module

class httpserver.httpserver.HttpProtocol(host, folder, event_loop=None, timeout=15)[source]

Bases: asyncio.protocols.Protocol

HTTP/1.1 Protocol implementation

Per connection made, one of these gets instantiated

connection_lost(exception)[source]

Called when the connection is lost or closed.

The argument is either an exception object or None. The latter means a regular EOF is received, or the connection was aborted or closed by this side of the connection.

connection_made(transport)[source]

Called when the connection is made

data_received(data)[source]

Process received data from the socket

Called when we receive data

exception httpserver.httpserver.InvalidRequestError(code, *args, **kwargs)[source]

Bases: Exception

Raised for invalid requests. Contains the error code.

This exception can be transformed to a http response.

get_http_response()[source]

Get this exception as an HTTP response suitable for output

Module contents

httpserver.run(argv=None)[source]

Run the HTTP server

Usage:
httpserver [options] [<folder>]

Options:

-h,--host=<hostname>        What host name to serve (default localhost)
-a,--bindaddress=<address>  Address to bind to (default 127.0.0.1)
-p,--port=<port>            Port to listen on (default 8080)
-v,--verbose                Increase verbosity to INFO messages
-d,--debug                  Increase verbosity to DEBUG messages
--help                      Print this help message
--version                   Print the version

To serve /path/to/www on all (ipv4) addresses for host myserver on port 80:

httpserver -a 0.0.0.0 -p 80 -h myserver /path/to/www