Google chrome 使用HTTP/2设置Quart服务器
我正在尝试设置一个Quart服务器来使用HTTP/2。我一直在尝试浏览以下最低限度的文档:Google chrome 使用HTTP/2设置Quart服务器,google-chrome,http2,quart,Google Chrome,Http2,Quart,我正在尝试设置一个Quart服务器来使用HTTP/2。我一直在尝试浏览以下最低限度的文档: 我有: $ cat app.py from quart import Quart, render_template, websocket app = Quart(__name__) @app.route("/") async def hello(): return await render_template("index.html") @app.
$ cat app.py
from quart import Quart, render_template, websocket
app = Quart(__name__)
@app.route("/")
async def hello():
return await render_template("index.html")
@app.route("/api")
async def json():
return {"hello": "world"}
@app.websocket("/ws")
async def ws():
while True:
await websocket.send("hello")
await websocket.send_json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5001)
一些基本检查:
$ curl -I --http2 http://acme.corp:5001
HTTP/1.1 101
date: Tue, 02 Mar 2021 10:05:12 GMT
server: hypercorn-h11
connection: upgrade
upgrade: h2c
HTTP/2 200
content-type: text/html; charset=utf-8
content-length: 0
date: Tue, 02 Mar 2021 10:05:12 GMT
server: hypercorn-h2
查看输出
$ python3 app.py
* Serving Quart app 'app'
* Environment: production
* Please use an ASGI server (e.g. Hypercorn) directly in production
* Debug mode: False
* Running on http://0.0.0.0:5001 (CTRL + C to quit)
[2021-03-02 11:01:49,083] Running on http://0.0.0.0:5001 (CTRL + C to quit)
[2021-03-02 11:01:53,011] 10.221.0.114:53637 GET / 1.1 200 0 5817
[2021-03-02 11:01:53,255] 10.221.0.114:53637 GET /favicon.ico 1.1 404 103 1348
以下是我从chrome加载index.html页面时看到的内容:
从chrome获取http/2,我缺少什么?本地您正在将不安全的http 1.1请求升级为不安全的http 2请求。这适用于Quart和curl,但包括chrome在内的浏览器也适用。为了让它在chrome中工作,我创建了一个自签名证书,将certfile和keyfile选项传递给run,并在访问站点时接受chrome提供的警告。有一个例子