我们的旧 Tomcat 服务器版本为
8.5.81
我们计划升级到 HTTP/2,以获得更快的 api 响应时间(优化)
以下配置已应用于
server.xml
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
</Connector>
但是调用仍然保留在 HTTP/1.1 上
需要帮助..
请求必须明确请求 HTTP/2 协议,可以通过 HTTP/1.1 协议升级或直接
协议升级:
要求:
GET /sample/hello HTTP/1.1
Connection: Upgrade, HTTP2-Settings
curl --verbose --http2 http://localhost:8080/sample/hello
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /sample/hello HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.0.1
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA
>
< HTTP/1.1 101
< Connection: Upgrade
< Upgrade: h2c
< Date: Thu, 24 Aug 2023 18:11:37 GMT
* Received 101, Switching to HTTP/2
< HTTP/2 200
< content-type: text/html;charset=ISO-8859-1
< content-length: 311
< date: Thu, 24 Aug 2023 18:11:37 GMT
(response redacted)
直接请求
要求:
GET /sample/hello HTTP/2
curl --verbose --http2-prior-knowledge http://localhost:8080/sample/hello
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* h2h3 [:method: GET]
* h2h3 [:path: /sample/hello]
* h2h3 [:scheme: http]
* h2h3 [:authority: localhost:8080]
* h2h3 [user-agent: curl/8.0.1]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x558d436ecf40)
> GET /sample/hello HTTP/2
> Host: localhost:8080
> user-agent: curl/8.0.1
> accept: */*
>
< HTTP/2 200
< content-type: text/html;charset=ISO-8859-1
< content-length: 311
< date: Thu, 24 Aug 2023 18:14:01 GMT
<
(response redacted)
如果没有明确请求 HTTP/2,将提供 HTTP/1.1
curl --verbose http://localhost:8080/sample/hello
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /sample/hello HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 311
< Date: Thu, 24 Aug 2023 18:18:39 GMT
<
使用此配置进行测试
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443">
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
</Connector>