[mod] by default allow only HTTPS, not HTTP

Related to https://github.com/searx/searx/pull/2373
This commit is contained in:
Alexandre Flament 2021-03-08 11:35:08 +01:00
parent 0d8b369b5b
commit 99e0651cea
7 changed files with 22 additions and 36 deletions

View file

@ -91,9 +91,10 @@ class SessionSinglePool(requests.Session):
self.adapters.clear()
https_adapter = threadLocal.__dict__.setdefault('https_adapter', next(https_adapters))
http_adapter = threadLocal.__dict__.setdefault('http_adapter', next(http_adapters))
self.mount('https://', https_adapter)
self.mount('http://', http_adapter)
if get_enable_http_protocol():
http_adapter = threadLocal.__dict__.setdefault('http_adapter', next(http_adapters))
self.mount('http://', http_adapter)
def close(self):
"""Call super, but clear adapters since there are managed globaly"""
@ -106,6 +107,17 @@ def set_timeout_for_thread(timeout, start_time=None):
threadLocal.start_time = start_time
def set_enable_http_protocol(enable_http):
threadLocal.enable_http = enable_http
def get_enable_http_protocol():
try:
return threadLocal.enable_http
except AttributeError:
return False
def reset_time_for_thread():
threadLocal.total_time = 0