I am aware of HTTP/2 Client provided by Java 9 and while trying out the incubator module with the following code:
// 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
I received this as an output :
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)
Moving down the stack trace I could find GOAWAY
listed as one of types of
jdk.incubator.http.internal.frame.Http2Frame
but then the internal class is not much documented to find exactly what does this type represent. I tried searching for the same on links from the JEPs as well, but couldn't find any.
Q. What is a GoAway Frame? When and how is it used?
Q. Why if I change my code to use a client without following redirects trying to GET "stackoverflow.com" I do not get the same exception?
HttpClient httpClient = HttpClient.newBuilder().build();
As set in the specifications,
The GOAWAY frame (type=0x7) is used to initiate graceful shutdown of a connection by a server.
It is likely that the frame is sent by the server on the second connection, the one following the redirect.
Do all URLs at stackoverflow.com accept http/2 connections ? That does not seem to be the case when looking at the indicator of my HTTP/2-SPDY browser plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With