[common] implement getHttps

This commit is contained in:
Mort Yao 2022-04-19 15:34:26 +02:00
parent 16b75f0497
commit 9ef6c2ff6d
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -342,6 +342,23 @@ def undeflate(data):
return decompressobj.decompress(data)+decompressobj.flush()
# an http.client implementation of get_content()
# because urllib does not support "Connection: keep-alive"
def getHttps(host, url, headers, debuglevel=0):
import http.client
conn = http.client.HTTPSConnection(host)
conn.set_debuglevel(debuglevel)
conn.request("GET", url, headers=headers)
resp = conn.getresponse()
data = resp.read()
data = ungzip(data)
#data = undeflate(data)
return str(data, encoding='utf-8')
# DEPRECATED in favor of get_content()
def get_response(url, faker=False):
logging.debug('get_response: %s' % url)