AD_VPN / app.py
tianlong12's picture
Update app.py
c6d1186 verified
import requests
from flask import Flask, Response, request
app = Flask(__name__)
@app.route('/')
def proxy_subscription():
url = 'http://testt.leov.asia/linuxdo/airport.php'
try:
# 获取订阅链接
response = requests.get(url)
if response.status_code == 200:
subscription_url = response.text.strip()
# 构造模拟 Clash 的请求头
headers = {
'User-Agent': 'Clash',
'Accept': 'application/vnd.clash.config'
}
# 获取订阅内容
subscription_response = requests.get(subscription_url, headers=headers)
if subscription_response.status_code == 200:
content = subscription_response.text
# 创建响应对象
resp = Response(content, mimetype='text/plain')
# 复制重要的头信息
headers_to_copy = ['subscription-userinfo', 'profile-update-interval', 'content-disposition']
for header in headers_to_copy:
if header in subscription_response.headers:
resp.headers[header] = subscription_response.headers[header]
return resp
else:
return "Failed to fetch the subscription content", 500
else:
return "Failed to fetch the subscription link", 500
except Exception as e:
return f"An error occurred: {str(e)}", 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)