Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
wouiSB committed Jun 5, 2024
2 parents ed14b6c + 2ce4c46 commit 0cf329e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def provider(request: Request):
headers = {'Content-Type': 'text/yaml;charset=utf-8'}
url = request.query_params.get("url")
async with httpx.AsyncClient() as client:
resp = await client.get(url, headers={'User-Agent':'clash-verge'})
resp = await client.get(url, headers={'User-Agent':request.headers['User-Agent']})
if resp.status_code < 200 or resp.status_code >= 400:
raise HTTPException(status_code=resp.status_code, detail=resp.text)
result = await parse.parseSubs(resp.text)
Expand Down Expand Up @@ -165,13 +165,13 @@ async def sub(request: Request):
headers = {'Content-Type': 'text/yaml;charset=utf-8'}
# if there's only one subscription, return userinfo
if length(url) == 1:
resp = await client.head(url[0], headers={'User-Agent':'clash-verge'})
resp = await client.head(url[0], headers={'User-Agent':request.headers['User-Agent']})
if resp.status_code < 200 or resp.status_code >= 400:
raise HTTPException(status_code=resp.status_code, detail=resp.text)
elif resp.status_code >= 300 and resp.status_code < 400:
while resp.status_code >= 300 and resp.status_code < 400:
url[0] = resp.headers['Location']
resp = await client.head(url[0], headers={'User-Agent':'clash-verge'})
resp = await client.head(url[0], headers={'User-Agent':request.headers['User-Agent']})
if resp.status_code < 200 or resp.status_code >= 400:
raise HTTPException(status_code=resp.status_code, detail=resp.text)
originalHeaders = resp.headers
Expand All @@ -184,7 +184,7 @@ async def sub(request: Request):
if url is not None:
for i in range(len(url)):
# the test of response
respText = (await client.get(url[i], headers={'User-Agent':'clash-verge'})).text
respText = (await client.get(url[i], headers={'User-Agent':request.headers['User-Agent']})).text
content.append(await parse.parseSubs(respText))
url[i] = "{}provider?{}".format(request.base_url, urlencode({"url": url[i]}))
if len(content) == 0:
Expand All @@ -205,7 +205,7 @@ async def proxy(url: str):
# file was big so use stream
async def stream():
async with httpx.AsyncClient() as client:
async with client.stream("GET", url, headers={'User-Agent':'clash-verge'}) as resp:
async with client.stream("GET", url, headers={'User-Agent':request.headers['User-Agent']}) as resp:
yield resp.status_code
yield resp.headers
if resp.status_code < 200 or resp.status_code >= 400:
Expand Down

0 comments on commit 0cf329e

Please sign in to comment.