Created
November 11, 2022 11:11
-
-
Save ljmccarthy/0945f6e6a40b1c7911131a0f35578615 to your computer and use it in GitHub Desktop.
The world's stupidest HTTP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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