add ability to set custom timeouts for http client in SpotifyHttpManager
@@ -36,6 +36,9 @@ public class SpotifyHttpManager implements IHttpManager {
private final UsernamePasswordCredentials proxyCredentials;
private final Integer cacheMaxEntries;
private final Integer cacheMaxObjectSize;
+ private final Integer connectionRequestTimeout;
+ private final Integer connectTimeout;
+ private final Integer socketTimeout;
/**
* Construct a new SpotifyHttpManager instance.
@@ -47,6 +50,9 @@ public class SpotifyHttpManager implements IHttpManager {
this.proxyCredentials = builder.proxyCredentials;
this.cacheMaxEntries = builder.cacheMaxEntries;
this.cacheMaxObjectSize = builder.cacheMaxObjectSize;
+ this.connectionRequestTimeout = builder.connectionRequestTimeout;
+ this.connectTimeout = builder.connectTimeout;
+ this.socketTimeout = builder.socketTimeout;
CacheConfig cacheConfig = CacheConfig.custom()
@@ -73,6 +79,15 @@ public class SpotifyHttpManager implements IHttpManager {
.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setProxy(proxy)
+ .setConnectionRequestTimeout(builder.connectionRequestTimeout != null
+ ? builder.connectionRequestTimeout
+ : RequestConfig.DEFAULT.getConnectionRequestTimeout())
+ .setConnectTimeout(builder.connectTimeout != null
+ ? builder.connectTimeout
+ : RequestConfig.DEFAULT.getConnectTimeout())
+ .setSocketTimeout(builder.socketTimeout != null
+ ? builder.socketTimeout
+ : RequestConfig.DEFAULT.getSocketTimeout())
.build();
@@ -112,6 +127,18 @@ public class SpotifyHttpManager implements IHttpManager {
return cacheMaxObjectSize;
}
+ public Integer getConnectionRequestTimeout() {
+ return connectionRequestTimeout;
+ }
+
+ public Integer getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ public Integer getSocketTimeout() {
+ return socketTimeout;
+ }
+
@Override
public String get(URI uri, Header[] headers) throws
IOException,
@@ -296,6 +323,9 @@ public class SpotifyHttpManager implements IHttpManager {
private UsernamePasswordCredentials proxyCredentials;
private Integer cacheMaxEntries;
private Integer cacheMaxObjectSize;
+ private Integer connectionRequestTimeout;
+ private Integer connectTimeout;
+ private Integer socketTimeout;
public Builder setProxy(HttpHost proxy) {
this.proxy = proxy;
@@ -317,6 +347,21 @@ public class SpotifyHttpManager implements IHttpManager {
return this;
}
+ public Builder setConnectionRequestTimeout(Integer connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ return this;
+ }
+
+ public Builder setConnectTimeout(Integer connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ return this;
+ }
+
+ public Builder setSocketTimeout(Integer socketTimeout) {
+ this.socketTimeout = socketTimeout;
+ return this;
+ }
+
public SpotifyHttpManager build() {
return new SpotifyHttpManager(this);
}
