httpserver package


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


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.


Called when the connection is made


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 this exception as an HTTP response suitable for output

Module contents[source]

Run the HTTP server

httpserver [options] [<folder>]


-h,--host=<hostname>        What host name to serve (default localhost)
-a,--bindaddress=<address>  Address to bind to (default
-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 -p 80 -h myserver /path/to/www