Add http3 module: HTTP/3 in the Java HTTP Client (JEP 517), opt-in, discovery modes, fallback timings, proxy downgrade and a packet-loss comparison
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpOption;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
|
||||
/** How long does the first request take, and which version answers, for each way of asking for HTTP/3? */
|
||||
public class Fallback {
|
||||
public static void main(String[] args) throws Exception {
|
||||
URI uri = URI.create(args[0]);
|
||||
long limitSeconds = Long.parseLong(args[1]);
|
||||
for (String mode : new String[] {"request HTTP_3 (ANY)", "client HTTP_3 (ANY)", "request HTTP_3_URI_ONLY"}) {
|
||||
var cb = Tls.builder();
|
||||
if (mode.startsWith("client")) cb.version(HttpClient.Version.HTTP_3);
|
||||
var rb = HttpRequest.newBuilder(uri).timeout(Duration.ofSeconds(limitSeconds));
|
||||
if (!mode.startsWith("client")) rb.version(HttpClient.Version.HTTP_3);
|
||||
if (mode.endsWith("URI_ONLY")) rb.setOption(HttpOption.H3_DISCOVERY, HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY);
|
||||
long t0 = System.nanoTime();
|
||||
String result;
|
||||
try (var client = cb.build()) {
|
||||
result = client.send(rb.build(), HttpResponse.BodyHandlers.ofString()).version().toString();
|
||||
} catch (Exception e) {
|
||||
result = e.getClass().getName() + ": " + e.getMessage();
|
||||
}
|
||||
System.out.printf("%-26s -> %-70s after %5d ms%n", mode, result, (System.nanoTime() - t0) / 1_000_000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user