on master help sign in
[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.

commit74d56f6cfb0dc8e30a6d4f95cce09937984cda2d authorAlexandre Flament <alex@al-f.net> dateTue 9 Feb 2021, 14:33 (6 years ago) parentf03ad0a
1 file changed+7−5
searx/poolrequests.py+7−5
searx/poolrequests.py+7−5
@@ -1,7 +1,7 @@
11import sys
22from time import time
33from itertools import cycle
4−from threading import RLock, local
4+from threading import local
55
66import requests
77
@@ -88,10 +88,12 @@ class SessionSinglePool(requests.Session):
8888 super().__init__()
8989
9090 # reuse the same adapters
91− with RLock():
92− self.adapters.clear()
93− self.mount('https://', next(https_adapters))
94− self.mount('http://', next(http_adapters))
91+ self.adapters.clear()
92+
93+ https_adapter = threadLocal.__dict__.setdefault('https_adapter', next(https_adapters))
94+ http_adapter = threadLocal.__dict__.setdefault('http_adapter', next(http_adapters))
95+ self.mount('https://', https_adapter)
96+ self.mount('http://', http_adapter)
9597
9698 def close(self):
9799 """Call super, but clear adapters since there are managed globaly"""