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,26 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.net.http.HttpClient;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
/** Trusts only the self-signed test certificate in certs/cert.pem (made by server/make-cert.sh). */
|
||||
final class Tls {
|
||||
static SSLContext context() throws Exception {
|
||||
KeyStore ks = KeyStore.getInstance("PKCS12");
|
||||
ks.load(null);
|
||||
try (var in = new FileInputStream("certs/cert.pem")) {
|
||||
ks.setCertificateEntry("test", CertificateFactory.getInstance("X.509").generateCertificate(in));
|
||||
}
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
|
||||
tmf.init(ks);
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(null, tmf.getTrustManagers(), null);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static HttpClient.Builder builder() throws Exception {
|
||||
return HttpClient.newBuilder().sslContext(context());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user