on master help sign in
Update httpx and friends to 0.21.3 (#3121)
commit3ddd0f8944c98cddbc136d73adc25e4399a5cb18 authorAndy Jones <me@andyljones.com> dateSat 15 Jan 2022, 10:16 (5 years ago) parent321ddc9
9 files changed+28−27
.gitignore+2 docs/dev/engine_overview.rst+1−1 requirements.txt+2−2 searx/engines/yggtorrent.py+1−1 searx/network/__init__.py+3−3 searx/network/client.py+13−15 searx/search/checker/impl.py+1−1 searx/search/processors/online.py+4−3 searx/webapp.py+1−1
.gitignore+2
@@ -26,3 +26,5 @@ dist/
2626local/
2727gh-pages/
2828searx.egg-info/
29+.env
30+geckodriver.log
docs/dev/engine_overview.rst+1−1
@@ -171,7 +171,7 @@ headers set HTTP header information
171171data set HTTP data information
172172cookies set HTTP cookies
173173verify bool Performing SSL-Validity check
174−allow_redirects bool Follow redirects
174+follow_redirects bool Follow redirects
175175max_redirects int maximum redirects, hard limit
176176soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
177177raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
requirements.txt+2−2
@@ -7,10 +7,10 @@ lxml==4.6.3
77pygments==2.8.0
88python-dateutil==2.8.2
99pyyaml==6.0
10−httpx[http2]==0.19.0
10+httpx[http2]==0.21.3
1111Brotli==1.0.9
1212uvloop==0.16.0; python_version >= '3.7'
1313uvloop==0.14.0; python_version < '3.7'
14−httpx-socks[asyncio]==0.4.1
14+httpx-socks[asyncio]==0.7.2
1515langdetect==1.0.9
1616setproctitle==1.2.2
searx/engines/yggtorrent.py+1−1
@@ -39,7 +39,7 @@ cookies = dict()
3939def init(engine_settings=None):
4040 global cookies
4141 # initial cookies
42− resp = http_get(url, allow_redirects=False)
42+ resp = http_get(url, follow_redirects=False)
4343 if resp.ok:
4444 for r in resp.history:
4545 cookies.update(r.cookies)
searx/network/__init__.py+3−3
@@ -122,17 +122,17 @@ def request(method, url, **kwargs):
122122
123123
124124def get(url, **kwargs):
125− kwargs.setdefault('allow_redirects', True)
125+ kwargs.setdefault('follow_redirects', True)
126126 return request('get', url, **kwargs)
127127
128128
129129def options(url, **kwargs):
130− kwargs.setdefault('allow_redirects', True)
130+ kwargs.setdefault('follow_redirects', True)
131131 return request('options', url, **kwargs)
132132
133133
134134def head(url, **kwargs):
135− kwargs.setdefault('allow_redirects', False)
135+ kwargs.setdefault('follow_redirects', False)
136136 return request('head', url, **kwargs)
137137
138138
searx/network/client.py+13−15
@@ -30,17 +30,15 @@ logger = logger.getChild('searx.http.client')
3030LOOP = None
3131SSLCONTEXTS = {}
3232TRANSPORT_KWARGS = {
33− 'backend': 'asyncio',
3433 'trust_env': False,
3534}
3635
3736
38−async def close_connections_for_url(connection_pool: httpcore.AsyncConnectionPool, url: httpcore._utils.URL):
39− origin = httpcore._utils.url_to_origin(url)
40− logger.debug('Drop connections for %r', origin)
41− connections_to_close = connection_pool._connections_for_origin(origin)
37+async def close_connections_for_url(connection_pool: httpcore.AsyncConnectionPool, url: httpx._models.URL):
38+ logger.debug('Drop connections for %r', url.host)
39+ connections_to_close = [conn for conn in connection_pool._pool if conn._origin == url.host]
4240 for connection in connections_to_close:
43− await connection_pool._remove_from_pool(connection)
41+ connection_pool._pool.remove(connection)
4442 try:
4543 await connection.aclose()
4644 except httpx.NetworkError as e:
@@ -76,12 +74,12 @@ class AsyncProxyTransportFixed(AsyncProxyTransport):
7674 Note: AsyncProxyTransport inherit from AsyncConnectionPool
7775 """
7876
79− async def handle_async_request(self, method, url, headers=None, stream=None, extensions=None):
77+ async def handle_async_request(self, request: httpx.Request):
8078 retry = 2
8179 while retry > 0:
8280 retry -= 1
8381 try:
84− return await super().handle_async_request(method, url, headers, stream, extensions)
82+ return await super().handle_async_request(request)
8583 except (ProxyConnectionError, ProxyTimeoutError, ProxyError) as e:
8684 raise httpx.ProxyError(e)
8785 except OSError as e:
@@ -89,25 +87,25 @@ class AsyncProxyTransportFixed(AsyncProxyTransport):
8987 raise httpx.NetworkError(e)
9088 except httpx.RemoteProtocolError as e:
9189 # in case of httpx.RemoteProtocolError: Server disconnected
92− await close_connections_for_url(self, url)
90+ await close_connections_for_url(self, request.url)
9391 logger.warning('httpx.RemoteProtocolError: retry', exc_info=e)
9492 # retry
9593 except (httpx.NetworkError, httpx.ProtocolError) as e:
9694 # httpx.WriteError on HTTP/2 connection leaves a new opened stream
9795 # then each new request creates a new stream and raise the same WriteError
98− await close_connections_for_url(self, url)
96+ await close_connections_for_url(self, request.url)
9997 raise e
10098
10199
102100class AsyncHTTPTransportFixed(httpx.AsyncHTTPTransport):
103101 """Fix httpx.AsyncHTTPTransport"""
104102
105− async def handle_async_request(self, method, url, headers=None, stream=None, extensions=None):
103+ async def handle_async_request(self, request: httpx.Request):
106104 retry = 2
107105 while retry > 0:
108106 retry -= 1
109107 try:
110− return await super().handle_async_request(method, url, headers, stream, extensions)
108+ return await super().handle_async_request(request)
111109 except OSError as e:
112110 # socket.gaierror when DNS resolution fails
113111 raise httpx.ConnectError(e)
@@ -115,16 +113,16 @@ class AsyncHTTPTransportFixed(httpx.AsyncHTTPTransport):
115113 # httpx.CloseError: [Errno 104] Connection reset by peer
116114 # raised by _keepalive_sweep()
117115 # from https://github.com/encode/httpcore/blob/4b662b5c42378a61e54d673b4c949420102379f5/httpcore/_backends/asyncio.py#L198 # noqa
118− await close_connections_for_url(self._pool, url)
116+ await close_connections_for_url(self._pool, request.url)
119117 logger.warning('httpx.CloseError: retry', exc_info=e)
120118 # retry
121119 except httpx.RemoteProtocolError as e:
122120 # in case of httpx.RemoteProtocolError: Server disconnected
123− await close_connections_for_url(self._pool, url)
121+ await close_connections_for_url(self._pool, request.url)
124122 logger.warning('httpx.RemoteProtocolError: retry', exc_info=e)
125123 # retry
126124 except (httpx.ProtocolError, httpx.NetworkError) as e:
127− await close_connections_for_url(self._pool, url)
125+ await close_connections_for_url(self._pool, request.url)
128126 raise e
129127
130128
searx/search/checker/impl.py+1−1
@@ -76,7 +76,7 @@ def _is_url_image(image_url):
7676 a = time()
7777 try:
7878 network.set_timeout_for_thread(10.0, time())
79− r = network.get(image_url, timeout=10.0, allow_redirects=True, headers={
79+ r = network.get(image_url, timeout=10.0, follow_redirects=True, headers={
8080 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
8181 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
8282 'Accept-Language': 'en-US;q=0.5,en;q=0.3',
searx/search/processors/online.py+4−3
@@ -69,9 +69,10 @@ class OnlineProcessor(EngineProcessor):
6969 if max_redirects:
7070 request_args['max_redirects'] = max_redirects
7171
72− # allow_redirects
73− if 'allow_redirects' in params:
74− request_args['allow_redirects'] = params['allow_redirects']
72+ # follow_redirects
73+ if 'follow_redirects' in params:
74+ # httpx has renamed this parameter to 'follow_redirects'
75+ request_args['follow_redirects'] = params['follow_redirects']
7576
7677 # soft_max_redirects
7778 soft_max_redirects = params.get('soft_max_redirects', max_redirects or 0)
searx/webapp.py+1−1
@@ -941,7 +941,7 @@ def image_proxy():
941941 url=url,
942942 headers=headers,
943943 timeout=settings['outgoing']['request_timeout'],
944− allow_redirects=True,
944+ follow_redirects=True,
945945 max_redirects=20)
946946
947947 resp = next(stream)