in apps/k8s-io/test.py [0:0]
def do_get(url):
parsed = urlparse.urlparse(url)
path = parsed.path
if parsed.query:
path = '%s?%s' % (path, parsed.query)
if parsed.scheme == 'http':
conn = httplib.HTTPConnection(TARGET_IP)
elif parsed.scheme == 'https':
# We can't use plain old httplib.HTTPSConnection as we are connecting
# via IP address but need to verify the certificate chain based on the
# host name. HTTPSConnection isn't smart enough to pull out the host
# header. Instead we manually TLS wrap the socket for a HTTPConnection
# and override the hostname to verify.
conn = httplib.HTTPConnection(TARGET_IP, 443)
context = ssl.create_default_context()
if SSL_VERIFY_DISABLE:
context = ssl._create_unverified_context()
conn.connect()
conn.sock = context.wrap_socket(
conn.sock, server_hostname=parsed.netloc)
conn.request('GET', path, headers={'Host': parsed.netloc})
resp = conn.getresponse()
body = resp.read().decode('utf8')
resp.close()
conn.close()
return resp, body