From 9ef6c2ff6d88a00e4389f19126ce928da4136a03 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Tue, 19 Apr 2022 15:34:26 +0200 Subject: [PATCH] [common] implement getHttps --- src/you_get/common.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/you_get/common.py b/src/you_get/common.py index 473c3155..afd6dad2 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -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)