org.zodiac.feign.http2client.config.FeignHttp2ClientConfig Maven / Gradle / Ivy
The newest version!
package org.zodiac.feign.http2client.config;
import java.net.http.HttpClient;
import java.time.Duration;
import java.util.Objects;
//import org.springframework.boot.context.properties.NestedConfigurationProperty;
public class FeignHttp2ClientConfig {
public static final int MIN_PRIORITY = 1;
public static final int MAX_PRIORITY = 256;
private boolean enabled = false;
/**
* 连接超时。,默认:2000毫秒。
*/
private Duration connectionTimeout = Duration.ofMillis(2000);
/**
* 读取超时。默认:2000毫秒。
*/
private Duration readTimeout = Duration.ofMillis(2000);
/**
* HTTP/2请求的默认优先级,提供的值必须介于1(含)和256(含)。默认:-1。
*/
private Integer http2Priority;
/**
* 重定向规则。,默认:ALWAYS。
*/
//@NestedConfigurationProperty
private HttpClient.Redirect redirect = HttpClient.Redirect.ALWAYS;
/**
* HTTP 版本。,默认:HTTP_1_1。
*/
//@NestedConfigurationProperty
private HttpClient.Version httpVersion = HttpClient.Version.HTTP_1_1;
public FeignHttp2ClientConfig() {
super();
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Duration getConnectionTimeout() {
return connectionTimeout;
}
public FeignHttp2ClientConfig setConnectionTimeout(Duration connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
public Duration getReadTimeout() {
return readTimeout;
}
public FeignHttp2ClientConfig setReadTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
return this;
}
public Integer getHttp2Priority() {
return http2Priority;
}
public FeignHttp2ClientConfig setHttp2Priority(Integer http2Priority) {
if (isValidHttp2Priority(http2Priority)) {
this.http2Priority = http2Priority;
}
return this;
}
public HttpClient.Redirect getRedirect() {
return redirect;
}
public FeignHttp2ClientConfig setRedirect(HttpClient.Redirect redirect) {
this.redirect = redirect;
return this;
}
public HttpClient.Version getHttpVersion() {
return httpVersion;
}
public FeignHttp2ClientConfig setHttpVersion(HttpClient.Version httpVersion) {
this.httpVersion = httpVersion;
return this;
}
@Override
public int hashCode() {
return Objects.hash(connectionTimeout, enabled, readTimeout, redirect, httpVersion);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FeignHttp2ClientConfig other = (FeignHttp2ClientConfig)obj;
return Objects.equals(connectionTimeout, other.connectionTimeout) && enabled == other.enabled
&& Objects.equals(readTimeout, other.readTimeout) && redirect == other.redirect && httpVersion == other.httpVersion;
}
@Override
public String toString() {
return "FeignHttpClientConfig [enabled=" + enabled + ", connectionTimeout=" + connectionTimeout
+ ", readTimeout=" + readTimeout + ", redirect=" + redirect + ", httpVersion=" + httpVersion + "]";
}
public static boolean isValidHttp2Priority(Integer http2Priority) {
if (null == http2Priority)
return false;
int priority = http2Priority.intValue();
return priority >= MIN_PRIORITY && priority <= MAX_PRIORITY;
}
}