我在 Tomcat 7.0.75 上部署了一个 spring boot web 应用程序,我们最近使用 https 对其进行了保护,具有以下 server.xml:
<Connector port="8443"
protocol="HTTP/1.1"
SSLEnabled="true"
maxThreads="50"
server="web"
allowTrace="false"
keystoreFile="/app/certs/keystore.jks"
keystorePass="wouldntYouLikeToKnow"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
sslEnabledProtocols="TLSv1.1,TLSv1.2"
ciphers="TLS_...SHA"
maxSwallowSize="-1"
connectionTimeout="20000"
maxKeepAliveRequests="100"
socket.soKeepAlive="true"/>`
当我们转到 https 时,具有大型(多个 MB)json 响应主体的请求在报告 200 OK 响应代码后开始在 Chrome 中产生奇怪的警告消息。 IE 也无法完全下载响应。
它只是一直显示该警告,永远不会完成下载。小请求工作正常。从客户端的角度来看,请求尚未完成,因为 https 调用的成功函数和错误函数均未执行。如图所示,第一个字节的时间 (TTFB) 相对较快,但大部分时间都花在下载过程中,并且永远不会离开该阶段。 Tomcat 显然保持了 http 连接打开并且客户端仍在等待数据,因为当我关闭浏览器时,Tomcat 报告套接字关闭错误。有没有人知道发生了什么以及为什么大型响应下载永远不会通过 https 完成,但在 http 上可以正常工作?
编辑 1 这是从 Linux 调用的 curl 命令和响应。
curl -X GET https://host.com/context -H 'accept: application/json,
text/plain, */*' -H 'cache-control: no-cache' -H 'token: 12acdee7-ef76-
4147-98d2-d90e4414d4e6' -H 'user-name: vn62253' -H 'user-security-id: 1'
-k -I
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, DELETE
Access-Control-Expose-Headers: Content-disposition, Content-Type
Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-
Type, Access-Control-Request-Method, Access-Control-Request-Headers, User-
Security-Id, Token, User-Name, Client-TZ-Offset
X-Application-Context: Compliance_WS:8765
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Vary: Accept-Encoding
Date: Tue, 29 Aug 2017 14:33:47 GMT
Server: web
请您参考如下方法:
可以增加tomcat的默认超时时间。如果您可以使用像 ngnix 这样的负载均衡器,您可能会遇到这个问题,因为它的默认超时间隔为 1 分钟。