summaryrefslogtreecommitdiff
path: root/searx/poolrequests.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-02-09 14:33:36 +0100
committerAlexandre Flament <alex@al-f.net>2021-02-09 14:33:36 +0100
commit74d56f6cfb0dc8e30a6d4f95cce09937984cda2d (patch)
treef3593b2224db667bd666e3d7214831f68ba1d38a /searx/poolrequests.py
parentf03ad0a3c0d32d6f6389c7891d752da11c0e8534 (diff)
downloadsearxng-74d56f6cfb0dc8e30a6d4f95cce09937984cda2d.tar.gz
searxng-74d56f6cfb0dc8e30a6d4f95cce09937984cda2d.zip
[mod] poolrequests: for one (user request, engine) always use the same HTTPAdapter
The duckduckgo engine requires an additional request after the results have been sent. This commit makes sure that the second request uses the same HTTPAdapter = the same IP address, and the same proxy.
Diffstat (limited to 'searx/poolrequests.py')
-rw-r--r--searx/poolrequests.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/searx/poolrequests.py b/searx/poolrequests.py
index 25a6baed9..8b8681437 100644
--- a/searx/poolrequests.py
+++ b/searx/poolrequests.py
@@ -1,7 +1,7 @@
import sys
from time import time
from itertools import cycle
-from threading import RLock, local
+from threading import local
import requests
@@ -88,10 +88,12 @@ class SessionSinglePool(requests.Session):
super().__init__()
# reuse the same adapters
- with RLock():
- self.adapters.clear()
- self.mount('https://', next(https_adapters))
- self.mount('http://', next(http_adapters))
+ 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)
def close(self):
"""Call super, but clear adapters since there are managed globaly"""