下面列出了java.net.http.HttpClient.Version#java.net.http.HttpClient.Redirect 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SneakyThrows
private HttpClient buildClient() {
Builder builder = HttpClient.newBuilder();
if (!HttpOptionsPluginProvider.options().isHttp2Support()){
builder.version(Version.HTTP_1_1);
}
if (HttpOptionsPluginProvider.options().isUseProxy()) {
URL url = new URL(HttpOptionsPluginProvider.options().getProxyUrl());
builder.proxy(new ProxyExclusionRoutePlanner(url, HttpOptionsPluginProvider.options().getProxyExclusion()).java());
//we dont use Authenticator because it might result in an exception if there is a 401 response
// see https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.net.http/share/classes/jdk/internal/net/http/AuthenticationFilter.java#L263
//we manually add Proxy-Authorization header instead
// if (proxyCredentials != null) {
// builder.authenticator(new Authenticator() {
// @Override
// protected PasswordAuthentication getPasswordAuthentication() {
// return proxyCredentials;
// }
// });
// }
}
if (!HttpOptionsPluginProvider.options().isCertificateValidation()) {
disableSsl(builder);
}
if (HttpOptionsPluginProvider.options().isFollowRedirects()) {
builder.followRedirects(Redirect.ALWAYS);
}
setupSslLegacyProtocolSupport(builder);
return builder
.build();
}
public OreKitDataClient(List<String> urls) {
if (urls == null || urls.isEmpty()) {
throw new IllegalArgumentException("urls are blank. at least 1 is expected");
}
this.urls = urls;
this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMillis(TIMEOUT)).build();
}
public RestClient(String baseUrl) throws Exception {
if (baseUrl == null) {
this.baseUrl = "http://localhost:8097";
} else {
this.baseUrl = baseUrl;
}
this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
public R2ServerClient(Configuration config) {
this.config = config;
this.hostname = config.getProperty("r2server.hostname");
this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMillis(config.getInteger("r2server.connectionTimeout"))).build();
}
public NoIpClient(String hostname, String username, String password) {
this.hostname = hostname;
this.username = username;
this.password = password;
this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
public ExternalIpClient(String host) {
this.host = host;
this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
public Http2Client() {
this(HttpClient.newBuilder()
.followRedirects(Redirect.ALWAYS)
.version(Version.HTTP_2)
.build());
}