github-actions[bot] commited on
Commit
e3a0f57
·
1 Parent(s): 08a33bc

Update from GitHub Actions

Browse files
Files changed (1) hide show
  1. main.py +6 -9
main.py CHANGED
@@ -99,18 +99,16 @@ async def proxy(request: Request):
99
  env_token = os.environ.get('TOKEN')
100
  if env_token:
101
  # 从请求头获取Authorization
102
- auth_header = request.headers.get('Authorization')
103
- if not auth_header or not auth_header.startswith('Bearer '):
104
  raise HTTPException(
105
  status_code=401,
106
- detail="未提供有效的Authorization header",
107
- headers={"WWW-Authenticate": "Bearer"}
108
  )
109
 
110
- # 提取Bearer token
111
- token = auth_header.split(' ')[1]
112
  # 验证token
113
- if token != env_token:
114
  raise HTTPException(
115
  status_code=403,
116
  detail="Token无效"
@@ -143,8 +141,6 @@ async def proxy(request: Request):
143
  # 获取原始请求头
144
  headers = dict(request.headers)
145
  # 移除可能导致问题的头
146
- headers.pop("host", None)
147
- headers.pop("authorization", None)
148
  headers.pop("x-forwarded-for", None)
149
  headers.pop("x-forwarded-proto", None)
150
  headers.pop("x-forwarded-port", None)
@@ -152,6 +148,7 @@ async def proxy(request: Request):
152
  headers.pop("x-request-id", None)
153
  headers.pop("x-ip-token", None)
154
  headers.pop("x-direct-url", None)
 
155
  headers.pop("referer", None)
156
  print(f"{headers}")
157
 
 
99
  env_token = os.environ.get('TOKEN')
100
  if env_token:
101
  # 从请求头获取Authorization
102
+ auth_header = request.headers.get('x-ip-token')
103
+ if not auth_header:
104
  raise HTTPException(
105
  status_code=401,
106
+ detail="未提供有效的x-ip-token header",
107
+ headers={"WWW-Authenticate": "x-ip-token"}
108
  )
109
 
 
 
110
  # 验证token
111
+ if auth_header != env_token:
112
  raise HTTPException(
113
  status_code=403,
114
  detail="Token无效"
 
141
  # 获取原始请求头
142
  headers = dict(request.headers)
143
  # 移除可能导致问题的头
 
 
144
  headers.pop("x-forwarded-for", None)
145
  headers.pop("x-forwarded-proto", None)
146
  headers.pop("x-forwarded-port", None)
 
148
  headers.pop("x-request-id", None)
149
  headers.pop("x-ip-token", None)
150
  headers.pop("x-direct-url", None)
151
+ headers.pop("host", None)
152
  headers.pop("referer", None)
153
  print(f"{headers}")
154