veggiedefender / http-server

A minimal HTTP server implemented from scratch using Python sockets and threads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

http-server

A minimal, probably-definitely-not-RFC-compliant HTTP server with an almost flask-ish API implemented from scratch using Python sockets and threads

Don't use this for anything serious.

  • There is no live demo because I'm scared to put it online.

API Docs

Found here:

https://github.com/veggiedefender/http-server/blob/master/API.md

Dependencies

Zero outside of the standard library, of which this project only uses socket and threading.

This means you can clone and run this right away!

Note: Use python 3.6 or higher, because this uses f-strings.

Running

$ python app.py

What do you mean "flask-ish?"

It looks kind of like Flask on the surface (mainly the decorator based routing)

Flask:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

This thing:

from server import Server
app = Server()

@app.route("/")
def hello(request, response):
    response.body = "Hello World!"

Limitations

  • Does not implement all or most of HTTP
  • Pretty bad at the parts of HTTP it does implement
  • Super brittle, probably
  • See issues

About

A minimal HTTP server implemented from scratch using Python sockets and threads


Languages

Language:Python 100.0%