mirror of
https://github.com/searxng/searxng.git
synced 2024-12-03 16:06:28 +00:00
[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.
This commit is contained in:
parent
f03ad0a3c0
commit
74d56f6cfb
1 changed files with 7 additions and 5 deletions
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue