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

XXX Switch to recurls

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