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

时间:2017-09-25 06:36:39

标签: java http http-redirect http2 java-9

我知道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框架?何时以及如何使用?

问。 为什么我更改我的代码以使用客户端而没有按照重定向尝试GET“stackoverflow.com”我没有得到相同的异常?

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

2 个答案:

答案 0 :(得分:4)

specifications中设置,

  

GOAWAY帧(类型= 0x7)用于启动连接关闭或发出严重错误情况

服务器可能在第二个连接上发送帧,重定向后面的那个。

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

答案 1 :(得分:1)

从HTTP / 1.1重定向并通过TLS升级到HTTP / 2错误地包括升级标头。此问题已提交

https://bugs.openjdk.java.net/browse/JDK-8198709