【问题标题】:make flask return response header http1.1 instead http1.0使烧瓶返回响应头 http1.1 而不是 http1.0
【发布时间】:2019-11-25 07:50:31
【问题描述】:

当我使用烧瓶 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?

【问题讨论】:

标签: http flask request http-headers response


【解决方案1】:

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

WSGIRequestHandler.protocol_version = "HTTP/1.1"

将此行放在您的 run.app() 呼叫之前

【讨论】:

    猜你喜欢
    • 2019-05-03
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    相关资源
    最近更新 更多