FLASK 修改Server响应标头
原来的响应标头:
Connection:close
Content-Length:6427
Content-Type:text/html; charset=utf-8
Date:Tue, 14 Mar 2023 03:03:42 GMT
Server:Werkzeug/2.2.2 Python/3.10.7
Vary:Cookie
我想隐藏Server标头,可以通过覆盖 Flask.process_response() 方法来更改每个响应的服务器标头。如下所示(验证通过):
SERVER_NAME = 'lichun'
class localFlask(Flask):
def process_response(self, response):
# Every response will be processed here first
response.headers['server'] = SERVER_NAME
return (response)
app = localFlask(__name__)
同理也应该可以修改其他headers的内容。如下所示:
class localFlask(Flask):
def process_response(self, response):
# Every response will be processed here first
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] ='*'
return (response)