tests/get-with-headers.py
changeset 1111 df702ad9b314
parent 1106 a02b1025536c
child 1199 b9f44c378e62
equal deleted inserted replaced
1103:9459951761fb 1111:df702ad9b314
    19 
    19 
    20 reasons = {'Not modified': 'Not Modified'} # python 2.4
    20 reasons = {'Not modified': 'Not Modified'} # python 2.4
    21 
    21 
    22 tag = None
    22 tag = None
    23 def request(host, path, show):
    23 def request(host, path, show):
    24 
    24     assert not path.startswith('/'), path
    25     global tag
    25     global tag
    26     headers = {}
    26     headers = {}
    27     if tag:
    27     if tag:
    28         headers['If-None-Match'] = tag
    28         headers['If-None-Match'] = tag
    29 
    29 
    30     conn = httplib.HTTPConnection(host)
    30     conn = httplib.HTTPConnection(host)
    31     conn.request("GET", path, None, headers)
    31     conn.request("GET", '/' + path, None, headers)
    32     response = conn.getresponse()
    32     response = conn.getresponse()
    33     print response.status, reasons.get(response.reason, response.reason)
    33     print response.status, reasons.get(response.reason, response.reason)
    34     for h in [h.lower() for h in show]:
    34     for h in [h.lower() for h in show]:
    35         if response.getheader(h, None) is not None:
    35         if response.getheader(h, None) is not None:
    36             print "%s: %s" % (h, response.getheader(h))
    36             print "%s: %s" % (h, response.getheader(h))