/python-http-server-template

Educational HTTP server template in Python

Primary LanguagePythonThe UnlicenseUnlicense

Minimal educational HTTP server in Python

This is a minimal HTTP server for educational purposes, written in Python.

What it does

It serves the following URLs on http://localhost:8000:

  • /: A static page
  • /favicon.ico: A static file, www/favicon.png
  • /served: A simple page counter
  • Everything else will receive 404 Not Found

What it does not do

It is not a general-purpose (or production-ready) web server, serving arbitrary files.

Concepts

This can be used to convey the following concepts:

General

Python

Security

  • When extending to serve arbitrary files based on the URL, care should be taken that the URLs (after the initial /) should not start with . nor contain / or \. Directory traversal could be shown.
  • When extending to return user input as part of the contents (e.g., include the URL in the 404 error message or provide a simple server-side computation, e.g., °C → °F conversion), escaping should be used. Cross-Site-Scripting (XSS) could be demonstrated.