我需要将授权头从令牌替换为屏障
范例
@app.middleware("https")
async def replace_prefix_token(request: Request, call_next):
if "Authorization" in request.headers and request.headers["Authorization"].split()[0] == "Token":
request.headers["Authorization"] = request.headers["Authorization"].replace("Token", "Bearer")
response = await call_next(request)
return response
误差
TypeError: 'Headers' object does not support item assignment
1条答案
按热度按时间qco9c6ql1#
Headers
本身是一个不可变的对象,但是你可以尝试使用update
方法来修改header值: