使烧瓶返回响应标头http1.1而不是http1.0

时间:2019-11-25 07:50:31

标签: http flask request http-headers response

当我使用flask 1.1.1时,请求使用http1.1,但响应使用http1.0,

from flask import Flask, request, Response
import json

app = Flask(__name__)


@app.route('/', methods=['GET'])
def index():
    print(request.environ.get('SERVER_PROTOCOL'))
    return Response(json.dumps({'hi': 'hello'}))


if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)

终端打印为

127.0.0.1 - - [25/Nov/2019 14:42:14] "GET / HTTP/1.1" 200 -
 * Detected change in '/Users/tal/test_redis/flask_ttttt.py', reloading
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 840-568-290
HTTP/1.1

它返回

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 15
Server: Werkzeug/0.15.5 Python/3.7.3

如何将http版本1.0更改为1.1?

1 个答案:

答案 0 :(得分:0)

添加一行以指示WSGI服务的协议版本。

WSGIRequestHandler.protocol_version = "HTTP/1.1"

在您的run.app()通话之前插入此行