Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Created November 11, 2022 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmccarthy/0945f6e6a40b1c7911131a0f35578615 to your computer and use it in GitHub Desktop.
Save ljmccarthy/0945f6e6a40b1c7911131a0f35578615 to your computer and use it in GitHub Desktop.
The world's stupidest HTTP server
# The world's stupidest HTTP server
def http_serve_data(data, bind_address, bind_port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind((bind_address, bind_port))
sock.listen()
conn, addr = sock.accept()
with conn:
conn.recv(1024) # Read and discard request
conn.sendall(b'HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Length: ' + str(len(data)).encode('ascii') + b'\r\n\r\n')
conn.sendall(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment