org.zodiac.feign.http2client.config.Http2ClientFeignConsumerConfigurer Maven / Gradle / Ivy
The newest version!
package org.zodiac.feign.http2client.config;
import java.net.http.HttpClient;
import java.time.Duration;
import java.util.Optional;
import org.zodiac.feign.core.config.FeignConfigInfo;
import org.zodiac.feign.http2client.uitl.Http2ClientUtil;
import feign.Client;
import feign.http2client.Http2Client;
public abstract class Http2ClientFeignConsumerConfigurer {
private FeignConfigInfo feignConfigInfo;
protected Http2ClientFeignConsumerConfigurer(FeignConfigInfo feignConfigInfo) {
this.feignConfigInfo = feignConfigInfo;
}
protected HttpClient httpClient() {
HttpClient.Builder builder = HttpClient.newBuilder().version(
Http2ClientUtil.toHttp2ClientVersion(feignConfigInfo.getHttpVersion()))
.followRedirects(feignConfigInfo.isFollowRedirects() ? HttpClient.Redirect.ALWAYS : HttpClient.Redirect.NEVER)
.connectTimeout(Duration.ofMillis(feignConfigInfo.getConnectTimeoutMills()));
Optional.ofNullable(feignConfigInfo.getHttp2().getPriority()).ifPresent(p -> builder.priority(p));
return builder.build();
}
protected Client http2ClientFeignClient(HttpClient httpClient) {
Http2Client feignClient = new Http2Client(httpClient);
return feignClient;
}
}