Commit 3b097c11 authored by Łukasz Nowak's avatar Łukasz Nowak

XXX Switch to recurls

XXX: Do moar!
parent d900458e
......@@ -18,6 +18,7 @@
# See https://www.nexedi.com/licensing for rationale and options.
import re
import recurls
import requests
import sys
import traceback
......@@ -55,8 +56,8 @@ def request(
url,
timeout=TIMEOUT,
headers=None,
session=requests,
contact=None,
ip=None,
version=0,
):
......@@ -69,16 +70,18 @@ def request(
headers["User-Agent"] = getUserAgent(version, contact)
kwargs = {}
kwargs["stream"] = False
kwargs["timeout"] = timeout
kwargs["allow_redirects"] = False
kwargs["verify"] = True
if ip is not None:
kwargs["ip"] = ip
args = ["GET", url]
kwargs["headers"] = headers
try:
response = session.request(*args, **kwargs)
mimikra = recurls.Recurls()
response = mimikra.request(*args, **kwargs)
except requests.exceptions.SSLError:
# XXX Enter into unknown host
response = requests.models.Response()
......@@ -206,16 +209,13 @@ def checkHttpStatus(
parsed_url = urlparse(url)
hostname = parsed_url.hostname
request_kw = {"timeout": timeout}
session = requests.Session()
session.trust_env = False
request_kw["session"] = session
# SNI Support
if parsed_url.scheme == "https":
# Provide SNI support
base_url = urlunsplit(
(parsed_url.scheme, parsed_url.netloc, "", "", "")
)
session.mount(base_url, ForcedIPHTTPSAdapter(dest_ip=ip))
request_kw['ip'] = ip
ip_url = url
elif parsed_url.scheme == "http":
# Force IP location
......@@ -296,7 +296,7 @@ def checkHttpStatus(
url,
response.status_code,
header_dict,
response.elapsed.total_seconds(),
response.elapsed,
elapsed_fast,
elapsed_moderate,
status_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment