Merge pull request #10 from NoCLin/fix/zero-content-length
Some checks are pending
Deploy Jekyll with GitHub Pages dependencies preinstalled / build (push) Waiting to run
Deploy Jekyll with GitHub Pages dependencies preinstalled / deploy (push) Blocked by required conditions

fix: report content length as is for HEAD, accept more headers
This commit is contained in:
Junlin Liu 2024-07-06 09:38:05 +08:00 committed by GitHub
commit e6e2eae600
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,7 +67,7 @@ async def direct_proxy(
async with httpx.AsyncClient() as client:
req_headers = request.headers.mutablecopy()
for key in req_headers.keys():
if key not in ["user-agent", "accept", "authorization"]:
if key in ["host"]:
del req_headers[key]
httpx_req: HttpxRequest = client.build_request(
@ -79,18 +79,16 @@ async def direct_proxy(
httpx_req = await pre_process_request(request, httpx_req, pre_process)
upstream_response = await client.send(
httpx_req, follow_redirects=follow_redirects
httpx_req,
follow_redirects=follow_redirects,
)
res_headers = upstream_response.headers
res_headers = {key: value for key, value in upstream_response.headers.items()}
if request.method != "HEAD":
res_headers.pop("content-length", None)
res_headers.pop("content-encoding", None)
logger.info(
f"proxy {request.url} to {target_url} {upstream_response.status_code}"
)
content = upstream_response.content
response = Response(
headers=res_headers,