devork

E pur si muove

Seeing your browser's headers using python

Saturday, December 15, 2007

There's a very annoying website that won't send their CSS to my normal web browser (epiphany) which makes it rather ugly. However when I use iceweasel the CSS gets applied. Since both browsers use exactly the same rendering engine, gecko, on my machine as far as I know, I thought they must sniff the headers sent by my browser. So I needed to check the headers, Python to the rescue:

import BaseHTTPServer

class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write('<html><body><pre>')
        self.wfile.write(self.headers)
        self.wfile.write('</pre></body></html>')
        return

def main():
    try:
        server = BaseHTTPServer.HTTPServer(('', 80), MyHandler)
        print 'serving...'
        server.serve_forever()
    except KeyboardInterrupt:
        print 'ttfn'
        server.socket.close()

if __name__ == '__main__':
    main()

Running this as root (80 is a privileged port) will show you the headers sent by your browser to the server. It's so simple that it took me longer to write this post then to write that code.

Only a pity that it didn't help me solve my problem...

Saturday, December 15, 2007 | Labels: |

2 comments:

Richard Jones said...

See also TCPWatch from http://hathawaymix.org/Software/TCPWatch which I've used numerous times to debug web client / server strangeness.

(posting anonymously because Blogger won't let me log in)

Anonymous said...

firebug and fiddler also allow you to see http headers sent/received by your browser.

New comments are not allowed.

Subscribe to: Post Comments (Atom)