Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Dec 19, 2024
1 parent 76d145c commit 36d553d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uvloop
import asyncio
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import JSONResponse
import aiohttp
import os
from collections import deque
Expand Down Expand Up @@ -30,7 +31,6 @@ async def cleanup(self):
await self.session.close()



middleware = [
Middleware(
CORSMiddleware,
Expand Down Expand Up @@ -76,8 +76,6 @@ async def read_root():
name="Test a coc api endpoint, very high ratelimit, only for testing without auth",
include_in_schema=False)
async def test_endpoint(url: str, request: Request):
global KEYS

query_string = "&".join([f"{key}={value}" for key, value in request.query_params.items()])

headers = {"Accept": "application/json", "Authorization": f"Bearer {proxy.keys[0]}"}
Expand All @@ -90,25 +88,29 @@ async def test_endpoint(url: str, request: Request):

async with aiohttp.ClientSession() as session:
async with session.get(full_url, headers=headers) as api_response:
# Handle non-200 responses by raising an HTTPException
if api_response.status != 200:
content = await api_response.text()
raise HTTPException(status_code=api_response.status, detail=content)

item = await api_response.json()

return item
cache_headers = {}
for header in ['Cache-Control', 'Expires', 'ETag', 'Last-Modified']:
value = api_response.headers.get(header)
if value:
cache_headers[header] = value

# Return the JSON response along with the extracted cache headers
return JSONResponse(content=item, headers=cache_headers)


@app.post("/v1/{url:path}",
name="Test a coc api endpoint, very high ratelimit, only for testing without auth",
include_in_schema=False)
async def test_post_endpoint(url: str, request: Request):
global KEYS

# Extract query parameters
query_params = request.query_params
fields = query_params.get("fields")

# Remove the "fields" parameter from the query parameters
query_params = {key: value for key, value in query_params.items() if key != "fields"}
query_string = "&".join([f"{key}={value}" for key, value in query_params.items()])

Expand Down

0 comments on commit 36d553d

Please sign in to comment.