socktools.examples.simple_http

Overview

This module demonstrates a trivial webserver using the http_mixin module. Please note that it is NOT considered production-ready.

Python API

This module implements a toy http webserver where every URL returns a small HTML page.

class socktools.examples.simple_http.MyServer(bind=None, connect=None, handlers={}, timeout=10, tick_interval=0.25, sock=None, meta_sock=None, logger=None, no_async=False)[source]

Bases: socktools.http_mixin.HTTPMixin, socktools.tcp_sock.TCPSock

Simple http server

This class implements a trivial http server with some static content.

Note that unlike other protocols and sockets, when dealing with HTTP the msg_data object has a reply() method that must be used.

get_default_handlers()[source]
handle_get(from_addr, msg_type, msg_data)[source]

Handle HTTP GET requests

The HTTP mixin represents requests as a special object with a reply() method that can be used to send a response.