Update app.py
Browse files
app.py
CHANGED
|
@@ -199,6 +199,38 @@ async def plain(
|
|
| 199 |
return PlainTextResponse("\n".join(p["proxy_url"] for p in px))
|
| 200 |
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
@app.post("/feedback")
|
| 203 |
async def feedback(proxy_url: str = Query(...), success: bool = Query(...)):
|
| 204 |
if success:
|
|
|
|
| 199 |
return PlainTextResponse("\n".join(p["proxy_url"] for p in px))
|
| 200 |
|
| 201 |
|
| 202 |
+
@app.get("/proxy.pac")
|
| 203 |
+
async def pac(
|
| 204 |
+
strategy: str = Query("round-robin"),
|
| 205 |
+
protocol: str = Query(None),
|
| 206 |
+
verified: bool = Query(False),
|
| 207 |
+
):
|
| 208 |
+
funcs = {
|
| 209 |
+
"round-robin": pool.get_round_robin,
|
| 210 |
+
"random": pool.get_random,
|
| 211 |
+
"fastest": pool.get_fastest,
|
| 212 |
+
"least-used": pool.get_least_used,
|
| 213 |
+
}
|
| 214 |
+
f = funcs.get(strategy)
|
| 215 |
+
if not f:
|
| 216 |
+
raise HTTPException(400, "Bad strategy")
|
| 217 |
+
|
| 218 |
+
entry = f(protocol, verified)
|
| 219 |
+
if not entry:
|
| 220 |
+
raise HTTPException(503, "No proxy available")
|
| 221 |
+
|
| 222 |
+
proxy = entry.proxy_url # ex: "123.45.67.89:8080"
|
| 223 |
+
|
| 224 |
+
pac_script = f"""
|
| 225 |
+
function FindProxyForURL(url, host) {{
|
| 226 |
+
return "PROXY {proxy}";
|
| 227 |
+
}}
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
return PlainTextResponse(pac_script, media_type="application/x-ns-proxy-autoconfig")
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
|
| 234 |
@app.post("/feedback")
|
| 235 |
async def feedback(proxy_url: str = Query(...), success: bool = Query(...)):
|
| 236 |
if success:
|