Created
September 13, 2015 16:04
-
-
Save mgedmin/c6cc118fb08cabe98273 to your computer and use it in GitHub Desktop.
Tiny webserver for debugging https://github.com/gtimelog/gtimelog/issues/60
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/python | |
import datetime | |
import pprint | |
import hashlib | |
from wsgiref.simple_server import make_server | |
def app(environ, start_response): | |
pprint.pprint(environ) | |
now = str(datetime.datetime.now()) | |
etag = '"%s"' % hashlib.sha1(now).hexdigest() | |
headers = [ | |
('Content-Type', 'text/plain'), | |
('ETag', etag), | |
('Cache-Control', 'max-age=300'), | |
('Expires', (datetime.datetime.utcnow() + datetime.timedelta(minutes=5)).strftime('%a, %d %b %Y %H:%M:%S GMT')), | |
] | |
pprint.pprint(headers) | |
start_response("200 OK", headers) | |
return [now] | |
if __name__ == '__main__': | |
try: | |
make_server('localhost', 8080, app).serve_forever() | |
except KeyboardInterrupt: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment