Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created September 13, 2015 16:04
Show Gist options
  • Save mgedmin/c6cc118fb08cabe98273 to your computer and use it in GitHub Desktop.
Save mgedmin/c6cc118fb08cabe98273 to your computer and use it in GitHub Desktop.
#!/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