Initial commit
This commit is contained in:
27
proxy/rss_proxy.py
Executable file
27
proxy/rss_proxy.py
Executable file
@@ -0,0 +1,27 @@
|
||||
import urllib.parse
|
||||
from flask import request, Response
|
||||
import requests
|
||||
import os
|
||||
from proxy import app
|
||||
|
||||
PROXY_URL = os.getenv("PROXY_URL")
|
||||
|
||||
@app.route("/proxy")
|
||||
def proxy():
|
||||
"""Proxy RSS feed with forced re-encoding to UTF-8"""
|
||||
raw_query = request.query_string.decode()
|
||||
if raw_query.startswith("url="):
|
||||
url = urllib.parse.unquote(raw_query[4:])
|
||||
else:
|
||||
return "Missing URL", 400
|
||||
|
||||
try:
|
||||
proxies = {"http": PROXY_URL, "https": PROXY_URL} if PROXY_URL else None
|
||||
r = requests.get(url, timeout=10, proxies=proxies)
|
||||
|
||||
r.encoding = "windows-1251" if "windows-1251" in r.headers.get("content-type", "").lower() else r.apparent_encoding
|
||||
response_text = r.text.replace('<?xml version="1.0" encoding="windows-1251"?>', '<?xml version="1.0" encoding="UTF-8"?>')
|
||||
|
||||
return Response(response_text, content_type="application/xml; charset=utf-8")
|
||||
except Exception as e:
|
||||
return f"Error: {e}", 500
|
||||
Reference in New Issue
Block a user