from
thk on 2008-05-18 18:02
python
,
programming
Since image files are served from the python handlers in madpy
python
,
programming
(notice that img src is in the form /somepath/path/image or /somepath/path/thumbnail and so on..)
, I needed a way to view their http headers.
I tried (and maybe still trying) to debug , caching , last-modified http header e.t.c.
I am trying to work with the last-modified http header to achieve image caching in the browser.
So I needed a way to view the http headers of a request. I believe the web developer firefox plugin has this functionality with plain pages but not with files.
Anyway I ended up writing this python script that retrieves and shows http headers of an http request and of course works with files as well.
def headers(uri):
import urllib2
request = urllib2.Request(uri)
opener = urllib2.build_opener()
firstdatastream = opener.open(request)
headersDict = firstdatastream.headers.dict
return headersDict
if __name__ == '__main__':
import sys
uri=''
if len(sys.argv) > 1:
uri = sys.argv[1]
if not uri:
uri = raw_input("enter url:")
print uri
print str(headers(uri))