gpt4 book ai didi

java - 什么是 Http2 中的 GoAway 框架以及它如何链接到重定向?

转载 作者:可可西里 更新时间:2023-11-01 16:26:23 25 4
gpt4 key购买 nike

我知道 HTTP/2 Client provided by Java 9并在使用以下代码试用孵化器模块时:

// Request builder
URI uri = new URI("http://www.stackoverflow.com/"); // using www.google.com gives me some payload with no exception
HttpRequest request = HttpRequest.newBuilder().uri(uri).GET().build();

// Client
HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build();
System.out.println(httpClient.version());

// Response builder
HttpResponse response = httpClient.send(request, HttpResponse.BodyHandler.asString());

System.out.println("statusCode = " + response.statusCode()); // 200 for google.com

我收到了这个作为输出:

Exception in thread "main" java.io.IOException: /192.168.0.2:60726: GOAWAY received
at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.handleGoAway(Http2Connection.java:613)
at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.handleConnectionFrame(Http2Connection.java:531)
at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.processFrame(Http2Connection.java:466)
at jdk.incubator.httpclient/jdk.incubator.http.internal.frame.FramesDecoder.decode(FramesDecoder.java:114)
at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection$FramesController.processReceivedData(Http2Connection.java:152)
at jdk.incubator.httpclient/jdk.incubator.http.Http2Connection.asyncReceive(Http2Connection.java:425)
at jdk.incubator.httpclient/jdk.incubator.http.AsyncSSLDelegate.upperRead(AsyncSSLDelegate.java:557)
at jdk.incubator.httpclient/jdk.incubator.http.internal.common.Queue.put(Queue.java:73)
at jdk.incubator.httpclient/jdk.incubator.http.AsyncSSLDelegate.asyncReceive(AsyncSSLDelegate.java:503)
at jdk.incubator.httpclient/jdk.incubator.http.PlainHttpConnection.asyncRead(PlainHttpConnection.java:300)
at jdk.incubator.httpclient/jdk.incubator.http.PlainHttpConnection$ReadEvent.handle(PlainHttpConnection.java:395)
at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:438)
at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:408)

向下移动堆栈跟踪,我可以找到 GOAWAY 列为

的一种类型
jdk.incubator.http.internal.frame.Http2Frame

但是内部类并没有太多的文档来准确地找到这个类型代表什么。我也尝试在 JEP 的链接上搜索相同内容,但找不到任何内容。

问。 什么是 GoAway 框架?何时以及如何使用它?

问。为什么如果我更改我的代码以使用客户端而不遵循尝试获取“stackoverflow.com”的重定向,我不会得到相同的异常?

HttpClient httpClient = HttpClient.newBuilder().build();

最佳答案

specifications 中设置,

The GOAWAY frame (type=0x7) is used to initiate graceful shutdown ofa connection by a server.

很可能该帧是由服务器在重定向后的第二个连接上发送的。

stackoverflow.com 上的所有 URL 都接受 http/2 连接吗?当查看我的 HTTP/2-SPDY 浏览器插件的指示器时,情况似乎并非如此。

关于java - 什么是 Http2 中的 GoAway 框架以及它如何链接到重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46398964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com