Skip to content

Instantly share code, notes, and snippets.

@sanand0
Created November 9, 2012 04:27
Show Gist options
  • Save sanand0/4043696 to your computer and use it in GitHub Desktop.
Save sanand0/4043696 to your computer and use it in GitHub Desktop.
Captures HTTP headers and saves them in a JSON file
"""
Captures all headers in a JSON file.
"""
import json
import tornado.ioloop
import tornado.web
import pprint
class Header(tornado.web.RequestHandler):
def get(self, path='', *args):
headers = self.request.headers
self.write('<pre>' + pprint.pformat(headers, indent=2) + '</pre>')
open('headers.json', 'a').write(json.dumps(headers))
application = tornado.web.Application([
(r'/.*', Header),
])
if __name__ == "__main__":
application.listen(9002)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment