HTTP/2:修订间差异
建立內容為「 == HTTP/2 Discovery == ;h2: HTTP/2 over TLS ;h2c: HTTP/2 is run over cleartext TCP === Starting HTTP/2 for "http" URIs=== 如果客户端无法事先知道服…」的新頁面 |
|||
第7行: | 第7行: | ||
如果客户端无法事先知道服务端是否支持http2,可以通过HTTP Upgrade mechanism(定义在HTTP/1.1)中来实现,这样在之后的请求中可以采取HTTP/2。 | 如果客户端无法事先知道服务端是否支持http2,可以通过HTTP Upgrade mechanism(定义在HTTP/1.1)中来实现,这样在之后的请求中可以采取HTTP/2。 | ||
< | <syntaxhighlight lang="lisp" inline> | ||
GET / HTTP/1.1 | GET / HTTP/1.1 | ||
Host: server.example.com | Host: server.example.com | ||
第13行: | 第13行: | ||
Upgrade: h2c | Upgrade: h2c | ||
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload> | HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload> | ||
</ | </syntaxhighlight> | ||
这样的话,如果请求中由payload必须一次性发完。然后才能升级到HTTP/2。另一种办法是通过<span class="article-label">OPTIONS</span>请求 | 这样的话,如果请求中由payload必须一次性发完。然后才能升级到HTTP/2。另一种办法是通过<span class="article-label">OPTIONS</span>请求 | ||
第20行: | 第20行: | ||
如果服务端不支持HTTP/2,返回中则不包含Upgrade header: | 如果服务端不支持HTTP/2,返回中则不包含Upgrade header: | ||
< | <syntaxhighlight lang="lisp" inline>HTTP/1.1 200 OK | ||
HTTP/1.1 200 OK | |||
Content-Length: 243 | Content-Length: 243 | ||
Content-Type: text/html | Content-Type: text/html | ||
</ | </syntaxhighlight> | ||
否则,返回一个101 (Switching Protocols)响应: | 否则,返回一个101 (Switching Protocols)响应: | ||
< | <syntaxhighlight lang="lisp" inline>HTTP/1.1 101 Switching Protocols | ||
HTTP/1.1 101 Switching Protocols | |||
Connection: Upgrade | Connection: Upgrade | ||
Upgrade: h2c | Upgrade: h2c | ||
</ | </syntaxhighlight> | ||
[[Category:Network]] | [[Category:Network]] |
2021年6月22日 (二) 14:11的版本
HTTP/2 Discovery
- h2
- HTTP/2 over TLS
- h2c
- HTTP/2 is run over cleartext TCP
Starting HTTP/2 for "http" URIs
如果客户端无法事先知道服务端是否支持http2,可以通过HTTP Upgrade mechanism(定义在HTTP/1.1)中来实现,这样在之后的请求中可以采取HTTP/2。
GET / HTTP/1.1 Host: server.example.com Connection: Upgrade, HTTP2-Settings Upgrade: h2c HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
这样的话,如果请求中由payload必须一次性发完。然后才能升级到HTTP/2。另一种办法是通过OPTIONS请求 来判断,这样做会多一次请求。
如果服务端不支持HTTP/2,返回中则不包含Upgrade header:
HTTP/1.1 200 OK Content-Length: 243 Content-Type: text/html
否则,返回一个101 (Switching Protocols)响应:
HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: h2c