Skip to content

Instantly share code, notes, and snippets.

@lehmannro
lehmannro / http.py
Created July 14, 2011 05:46
Simple HTTP Server in 512 bytes
#!/usr/bin/env python2.6
"""
Task: implement a rudimentary HTTP server in Python. It needs to support the
GET method to serve static HTML files. Requests to ``/`` shall be
automatically resolved to ``/index.html``. All invalid requests shall be
answered with a ``400 Bad Request``. Queries on a non-existing file shall
terminate in a ``404 Not Found``. The serving port shall be passed through the
command line. The server must be threaded. Use the socket APIs.
This implementation is *just a single Python expression,* and only 512 bytes.