@Override publicvoid handle(final HttpTestExchange exchange) throws IOException { // we only send informational response and then return for (int i = 0; i < 5; i++) {
exchange.sendResponseHeaders(102, -1);
System.out.println("Sent 102 response code from H2 server"); // wait for a while before sending again try { Thread.sleep(2000);
} catch (InterruptedException e) { // just return
System.err.println("Handler thread interrupted");
}
}
}
}
/** *TeststhatwhenaHTTP/1.1serversendsintermediate1xxresponsecodesandthenthefinal *response,theclient(internally)willignorethoseintermediateinformationalresponsecodes *andonlyreturnthefinalresponsetotheapplication
*/
@Test publicvoid test1xxForHTTP11() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); final URI[] requestURIs = new URI[]{ new URI(http1RequestURIBase + "/test/foo"), new URI(http1RequestURIBase + "/test/bar"), new URI(http1RequestURIBase + "/test/hello")}; for (final URI requestURI : requestURIs) { final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing request to " + requestURI); final HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); Assert.assertEquals(response.version(), HttpClient.Version.HTTP_1_1, "Unexpected HTTP version in response"); Assert.assertEquals(response.statusCode(), 200, "Unexpected response code"); Assert.assertEquals(response.body(), EXPECTED_RSP_BODY, "Unexpected response body");
}
}
/** *TeststhatwhenaHTTP2serversendsintermediate1xxresponsecodesandthenthefinal *response,theclient(internally)willignorethoseintermediateinformationalresponsecodes *andonlyreturnthefinalresponsetotheapplication
*/
@Test publicvoid test1xxForHTTP2() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); final URI[] requestURIs = new URI[]{ new URI(http2RequestURIBase + "/102"), new URI(http2RequestURIBase + "/103"), new URI(http2RequestURIBase + "/100")}; for (final URI requestURI : requestURIs) { final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing request to " + requestURI); final HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); Assert.assertEquals(response.version(), HttpClient.Version.HTTP_2, "Unexpected HTTP version in response"); Assert.assertEquals(response.statusCode(), 200, "Unexpected response code"); Assert.assertEquals(response.body(), EXPECTED_RSP_BODY, "Unexpected response body");
}
}
/** *Teststhatwhenarequestisissuedwithaspecificrequesttimeoutandtheserver *respondswithintermediate1xxresponsecodebutdoesn'trespondwithafinalresponsewithin *thetimeoutduration,thentheapplicationfailswitharequesttimeout
*/
@Test publicvoid test1xxRequestTimeout() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); final URI requestURI = new URI(http2RequestURIBase + "/only-informational"); final Duration requestTimeout = Duration.ofSeconds(2); final HttpRequest request = HttpRequest.newBuilder(requestURI).timeout(requestTimeout)
.build();
System.out.println("Issuing request to " + requestURI); // we expect the request to timeout Assert.assertThrows(HttpTimeoutException.class, () -> {
client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
});
}
/** *TeststhatwhentheHTTP/1.1serversendsa101responsewhentherequesthasn'tasked *foran"Upgrade"thentherequestfails.
*/
@Test publicvoid testHTTP11Unexpected101() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); final URI requestURI = new URI(http1RequestURIBase + "/test/bye"); final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing request to " + requestURI); // we expect the request to fail because the server sent an unexpected 101 Assert.assertThrows(ProtocolException.class,
() -> client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)));
}
/** *TeststhatwhentheHTTP2server(overHTTPS)sendsa101responsewhentherequest *hasn'taskedforan"Upgrade"thentherequestfails.
*/
@Test publicvoid testSecureHTTP2Unexpected101() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.sslContext(sslContext)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); final URI requestURI = new URI(https2RequestURIBase + "/101"); final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing request to " + requestURI); // we expect the request to fail because the server sent an unexpected 101 Assert.assertThrows(ProtocolException.class,
() -> client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)));
}
/** *TeststhatwhentheHTTP2server(overplainHTTP)sendsa101responsewhentherequest *hasn'taskedforan"Upgrade"thentherequestfails.
*/
@Test publicvoid testPlainHTTP2Unexpected101() throws Exception { final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.proxy(HttpClient.Builder.NO_PROXY).build();
TRACKER.track(client); // when using HTTP2 version against a "http://" (non-secure) URI // the HTTP client (implementation) internally initiates a HTTP/1.1 connection // and then does an "Upgrade:" to "h2c". This it does when there isn't already a // H2 connection against the target/destination server. So here we initiate a dummy request // using the client instance against the same target server and just expect it to return // back successfully. Once that connection is established (and internally pooled), the client // will then reuse that connection and won't issue an "Upgrade:" and thus we can then // start our testing
warmupH2Client(client); // start the actual testing final URI requestURI = new URI(http2RequestURIBase + "/101"); final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing request to " + requestURI); // we expect the request to fail because the server sent an unexpected 101 Assert.assertThrows(ProtocolException.class,
() -> client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)));
}
// sends a request and expects a 200 response back privatevoid warmupH2Client(final HttpClient client) throws Exception { final URI requestURI = new URI(http2RequestURIBase + "/200"); final HttpRequest request = HttpRequest.newBuilder(requestURI).build();
System.out.println("Issuing (warmup) request to " + requestURI); final HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding()); Assert.assertEquals(response.statusCode(), 200, "Unexpected response code");
}
// verifies that the HttpClient being tracked has no outstanding operations privatevoid assertNoOutstandingClientOps() throws AssertionError {
System.gc(); final AssertionError refCheckFailure = TRACKER.check(1000); if (refCheckFailure != null) { throw refCheckFailure;
} // successful test completion
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.