Created
December 1, 2015 03:35
-
-
Save thomasballinger/5621cc7859112eca98b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import socket | |
listener = socket.socket() | |
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
listener.bind(('', 8000)) | |
listener.listen(5) | |
while True: | |
s, addr = listener.accept() | |
print 'server received connection from', addr | |
request = s.recv(10000) | |
print 'request we received:', request | |
method, rest = request.split(' ', 1) | |
path, rest = rest.split(None, 1) | |
s.send('HTTP/0.9 200 OK\n\n') | |
with open('.'+path) as f: | |
s.sendall(f.read()) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment