forked from forks/microblog.pub
Tweak proxy client
This commit is contained in:
parent
a82f619e89
commit
0527e34476
1 changed files with 24 additions and 26 deletions
50
app/main.py
50
app/main.py
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue