Tweak proxy client

main
Thomas Sileo 2022-12-02 18:48:05 +01:00
parent a82f619e89
commit 0527e34476
1 changed files with 24 additions and 26 deletions

View File

@ -1179,36 +1179,34 @@ async def nodeinfo(
) )
proxy_client = httpx.AsyncClient(
follow_redirects=True,
timeout=httpx.Timeout(timeout=10.0),
transport=httpx.AsyncHTTPTransport(retries=1),
)
async def _proxy_get( async def _proxy_get(
request: starlette.requests.Request, url: str, stream: bool request: starlette.requests.Request, url: str, stream: bool
) -> httpx.Response: ) -> httpx.Response:
# Request the URL (and filter request headers) async with httpx.AsyncClient(
proxy_req = proxy_client.build_request( follow_redirects=True,
request.method, timeout=httpx.Timeout(timeout=10.0),
url, transport=httpx.AsyncHTTPTransport(retries=1),
headers=[ ) as proxy_client:
(k, v) # Request the URL (and filter request headers)
for (k, v) in request.headers.raw proxy_req = proxy_client.build_request(
if k.lower() request.method,
not in [ url,
b"host", headers=[
b"cookie", (k, v)
b"x-forwarded-for", for (k, v) in request.headers.raw
b"x-forwarded-proto", if k.lower()
b"x-real-ip", not in [
b"user-agent", b"host",
b"cookie",
b"x-forwarded-for",
b"x-forwarded-proto",
b"x-real-ip",
b"user-agent",
]
] ]
] + [(b"user-agent", USER_AGENT.encode())],
+ [(b"user-agent", USER_AGENT.encode())], )
) return await proxy_client.send(proxy_req, stream=stream)
return await proxy_client.send(proxy_req, stream=stream)
def _filter_proxy_resp_headers( def _filter_proxy_resp_headers(