39 headers['If-None-Match'] = tag |
39 headers['If-None-Match'] = tag |
40 |
40 |
41 conn = httplib.HTTPConnection(host) |
41 conn = httplib.HTTPConnection(host) |
42 conn.request("GET", '/' + path, None, headers) |
42 conn.request("GET", '/' + path, None, headers) |
43 response = conn.getresponse() |
43 response = conn.getresponse() |
44 print response.status, response.reason |
44 print(response.status, response.reason) |
45 if show[:1] == ['-']: |
45 if show[:1] == ['-']: |
46 show = sorted(h for h, v in response.getheaders() |
46 show = sorted(h for h, v in response.getheaders() |
47 if h.lower() not in show) |
47 if h.lower() not in show) |
48 for h in [h.lower() for h in show]: |
48 for h in [h.lower() for h in show]: |
49 if response.getheader(h, None) is not None: |
49 if response.getheader(h, None) is not None: |
50 print "%s: %s" % (h, response.getheader(h)) |
50 print("%s: %s" % (h, response.getheader(h))) |
51 if not headeronly: |
51 if not headeronly: |
52 print |
52 print() |
53 data = response.read() |
53 data = response.read() |
54 |
54 |
55 # Pretty print JSON. This also has the beneficial side-effect |
55 # Pretty print JSON. This also has the beneficial side-effect |
56 # of verifying emitted JSON is well-formed. |
56 # of verifying emitted JSON is well-formed. |
57 if formatjson: |
57 if formatjson: |
58 # json.dumps() will print trailing newlines. Eliminate them |
58 # json.dumps() will print trailing newlines. Eliminate them |
59 # to make tests easier to write. |
59 # to make tests easier to write. |
60 data = json.loads(data) |
60 data = json.loads(data) |
61 lines = json.dumps(data, sort_keys=True, indent=2).splitlines() |
61 lines = json.dumps(data, sort_keys=True, indent=2).splitlines() |
62 for line in lines: |
62 for line in lines: |
63 print line.rstrip() |
63 print(line.rstrip()) |
64 else: |
64 else: |
65 sys.stdout.write(data) |
65 sys.stdout.write(data) |
66 |
66 |
67 if twice and response.getheader('ETag', None): |
67 if twice and response.getheader('ETag', None): |
68 tag = response.getheader('ETag') |
68 tag = response.getheader('ETag') |