feat: support bbs oss proxy

This commit is contained in:
xtaodada 2023-05-26 23:47:16 +08:00
parent 7f4f6ca9a7
commit 8df84b165f
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 36 additions and 1 deletions

2
.gitignore vendored
View File

@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

31
main.py Normal file
View File

@ -0,0 +1,31 @@
from fastapi import FastAPI
from httpx import AsyncClient
from starlette.requests import Request
from starlette.responses import Response
app = FastAPI()
client = AsyncClient(
timeout=60.0,
)
@app.get('/upload/{file_path:path}')
async def proxy_cve_search_api(req: Request, file_path: str) -> Response:
headers = {}
for i in req.headers.items():
headers[i[0]] = i[1]
headers["host"] = "upload-bbs.miyoushe.com"
resp = await client.get(
f'https://upload-bbs.miyoushe.com/upload/{file_path}',
params=req.query_params,
headers=headers,
follow_redirects=True,
)
content = resp.content
return Response(content=content, status_code=resp.status_code, headers=dict(resp.headers))
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5677)

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
httpx==0.24.1
fastapi~=0.95.2
starlette~=0.27.0
uvicorn~=0.22.0