tests/get-with-headers.py
author Martin Geisler <mg@aragost.com>
Mon, 01 Nov 2010 10:24:07 +0100
branchstable
changeset 852 fb1e8925292d
parent 717 43efa35c5eed
child 1051 5b75af0ca224
permissions -rwxr-xr-x
run-tests: use regex when searching for $HGPORT in test output This prevents spurious errors when a changeset hash happens to match the port number. Before, this invocation gave a test failure: $ ./run-tests.py test-log.t --port 24427 ERROR: /home/mg/src/mercurial-crew/tests/test-log.t output changed --- /home/mg/src/mercurial-crew/tests/test-log.t +++ /home/mg/src/mercurial-crew/tests/test-log.t.err @@ -626,12 +626,12 @@ $ hg log -b default changeset: 2:c3a4f03cc9a7 - parent: 0:24427303d56f + parent: 0:$HGPORT303d56f user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: commit on default ... [ original upstream message ]

#!/usr/bin/env python

"""This does HTTP GET requests given a host:port and path and returns
a subset of the headers plus the body of the result."""

import httplib, sys, re

try:
    import msvcrt, os
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
except ImportError:
    pass

headers = [h.lower() for h in sys.argv[3:]]
conn = httplib.HTTPConnection(sys.argv[1])
conn.request("GET", sys.argv[2])
response = conn.getresponse()
print response.status, response.reason
for h in headers:
    if response.getheader(h, None) is not None:
        print "%s: %s" % (h, response.getheader(h))
print
data = response.read()
sys.stdout.write(data)

if 200 <= response.status <= 299:
    sys.exit(0)
sys.exit(1)