Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.*;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.util.Timeout;
Expand Down Expand Up @@ -75,14 +76,6 @@ public SpotifyHttpManager(Builder builder) {
);
}

ConnectionConfig connectionConfig = ConnectionConfig
.custom()
.setConnectTimeout(builder.connectTimeout != null
? Timeout.ofMilliseconds(builder.connectTimeout)
: ConnectionConfig.DEFAULT.getConnectTimeout())
.build();
BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
connectionManager.setConnectionConfig(connectionConfig);
RequestConfig requestConfig = RequestConfig
.custom()
.setCookieSpec(StandardCookieSpec.STRICT)
Expand All @@ -98,7 +91,7 @@ public SpotifyHttpManager(Builder builder) {
this.httpClient = HttpClients
.custom()
.disableContentCompression()
.setConnectionManager(connectionManager)
.setConnectionManager(builder.getConnectionManager())
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultRequestConfig(requestConfig)
.setProxy(proxy)
Expand All @@ -109,7 +102,7 @@ public SpotifyHttpManager(Builder builder) {
.custom()
.setCacheConfig(cacheConfig)
.disableContentCompression()
.setConnectionManager(connectionManager)
.setConnectionManager(builder.getConnectionManager())
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultRequestConfig(requestConfig)
.setProxy(proxy)
Expand Down Expand Up @@ -366,6 +359,7 @@ public static class Builder {
private Integer connectionRequestTimeout;
private Integer connectTimeout;
private Integer socketTimeout;
private HttpClientConnectionManager connectionManager;

public Builder setProxy(HttpHost proxy) {
this.proxy = proxy;
Expand Down Expand Up @@ -402,6 +396,26 @@ public Builder setSocketTimeout(Integer socketTimeout) {
return this;
}

public Builder setConnectionManager(HttpClientConnectionManager connectionManager) {
this.connectionManager = connectionManager;
return this;
}

HttpClientConnectionManager getConnectionManager() {
if (connectionManager == null) {
BasicHttpClientConnectionManager basicHttpClientConnectionManager = new BasicHttpClientConnectionManager();
basicHttpClientConnectionManager.setConnectionConfig(ConnectionConfig
.custom()
.setConnectTimeout(connectTimeout != null ?
Timeout.ofMilliseconds(connectTimeout) :
ConnectionConfig.DEFAULT.getConnectTimeout())
.build());
connectionManager = basicHttpClientConnectionManager;
}

return connectionManager;
}

public SpotifyHttpManager build() {
return new SpotifyHttpManager(this);
}
Expand Down