Skip to content

Commit

Permalink
[mod] searx.network: memory optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dalf committed Aug 25, 2023
1 parent 7d806d1 commit b723d6f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion searx/network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,40 @@ def get_sslcontexts(proxy_url=None, cert=None, verify=True, trust_env=True, http


class AsyncHTTPTransportNoHttp(httpx.AsyncHTTPTransport):
"""Block HTTP request"""
"""Block HTTP request
The constructor is blank because httpx.AsyncHTTPTransport.__init__ creates an SSLContext unconditionally:
https://github.com/encode/httpx/blob/0f61aa58d66680c239ce43c8cdd453e7dc532bfc/httpx/_transports/default.py#L271
Each SSLContext consumes more than 500kb of memory, since there is about one network per engine.
In consequence, this class overrides all public methods
For reference: https://github.com/encode/httpx/issues/2298
"""

def __init__(self, *args, **kwargs):
# pylint: disable=super-init-not-called
# this on purpose if the base class is not called
pass

async def handle_async_request(self, request):
raise httpx.UnsupportedProtocol('HTTP protocol is disabled')

async def aclose(self) -> None:
pass

async def __aenter__(self):
return self

async def __aexit__(
self,
exc_type=None,
exc_value=None,
traceback=None,
) -> None:
pass


class AsyncProxyTransportFixed(AsyncProxyTransport):
"""Fix httpx_socks.AsyncProxyTransport
Expand Down

0 comments on commit b723d6f

Please sign in to comment.