|
@@ -60,38 +60,42 @@ def static_proxy(path):
|
|
def proxy(path):
|
|
def proxy(path):
|
|
url = f'{TARGET_URL}/{path}'
|
|
url = f'{TARGET_URL}/{path}'
|
|
logger.info(f'接收到请求{url}')
|
|
logger.info(f'接收到请求{url}')
|
|
-
|
|
|
|
|
|
+ raw_body = request.get_data(cache=True)
|
|
# 获取 headers(排除 Host 避免冲突)
|
|
# 获取 headers(排除 Host 避免冲突)
|
|
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
|
|
headers = {key: value for key, value in request.headers if key.lower() != 'host'}
|
|
headers[
|
|
headers[
|
|
'User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
|
|
'User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36'
|
|
|
|
|
|
try:
|
|
try:
|
|
- if request.files:
|
|
|
|
|
|
+ if request.files or (request.content_type and 'multipart/form-data' in request.content_type.lower()):
|
|
# 构造 Multipart 表单
|
|
# 构造 Multipart 表单
|
|
fields = {}
|
|
fields = {}
|
|
|
|
|
|
# 添加普通字段
|
|
# 添加普通字段
|
|
- for key, value in request.form.items():
|
|
|
|
- fields[key] = value
|
|
|
|
|
|
+ if request.files:
|
|
|
|
+ for key, value in request.form.items():
|
|
|
|
+ fields[key] = value
|
|
|
|
|
|
# 添加文件字段
|
|
# 添加文件字段
|
|
- for key, file in request.files.items():
|
|
|
|
- fields[key] = (file.filename, file.stream, file.mimetype)
|
|
|
|
|
|
+ for key, file in request.files.items():
|
|
|
|
+ fields[key] = (file.filename, file.stream, file.mimetype)
|
|
|
|
|
|
- m = MultipartEncoder(fields=fields)
|
|
|
|
- headers['Content-Type'] = m.content_type
|
|
|
|
|
|
+ form_data = MultipartEncoder(fields=fields)
|
|
|
|
+ headers['Content-Type'] = form_data.content_type
|
|
|
|
+ else:
|
|
|
|
+ form_data = raw_body
|
|
|
|
|
|
resp = requests.request(
|
|
resp = requests.request(
|
|
method=request.method,
|
|
method=request.method,
|
|
url=url,
|
|
url=url,
|
|
headers=headers,
|
|
headers=headers,
|
|
params=request.args,
|
|
params=request.args,
|
|
- data=m,
|
|
|
|
|
|
+ data=form_data,
|
|
cookies=request.cookies,
|
|
cookies=request.cookies,
|
|
allow_redirects=False
|
|
allow_redirects=False
|
|
)
|
|
)
|
|
else:
|
|
else:
|
|
|
|
+ # JSON 或普通表单
|
|
json_data = None
|
|
json_data = None
|
|
form_data = None
|
|
form_data = None
|
|
if request.content_type and 'application/json' in request.content_type.lower():
|
|
if request.content_type and 'application/json' in request.content_type.lower():
|