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: 13 additions & 21 deletions src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.StandardCookieSpec;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
Expand All @@ -19,7 +18,8 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
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.impl.io.PoolingHttpClientConnectionManager;
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 All @@ -38,12 +38,12 @@ public class SpotifyHttpManager implements IHttpManager {
private static final Gson GSON = new Gson();
private final CloseableHttpClient httpClient;
private final CloseableHttpClient httpClientCaching;
private final HttpClientConnectionManager connectionManager;
private final HttpHost proxy;
private final UsernamePasswordCredentials proxyCredentials;
private final Integer cacheMaxEntries;
private final Integer cacheMaxObjectSize;
private final Integer connectionRequestTimeout;
private final Integer connectTimeout;
private final Integer socketTimeout;

/**
Expand All @@ -56,8 +56,8 @@ public SpotifyHttpManager(Builder builder) {
this.proxyCredentials = builder.proxyCredentials;
this.cacheMaxEntries = builder.cacheMaxEntries;
this.cacheMaxObjectSize = builder.cacheMaxObjectSize;
this.connectionManager = builder.connectionManager;
this.connectionRequestTimeout = builder.connectionRequestTimeout;
this.connectTimeout = builder.connectTimeout;
this.socketTimeout = builder.socketTimeout;

CacheConfig cacheConfig = CacheConfig.custom()
Expand All @@ -75,14 +75,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 Down Expand Up @@ -144,12 +136,12 @@ public Integer getCacheMaxObjectSize() {
return cacheMaxObjectSize;
}

public Integer getConnectionRequestTimeout() {
return connectionRequestTimeout;
public HttpClientConnectionManager getConnectionManager() {
return connectionManager;
}

public Integer getConnectTimeout() {
return connectTimeout;
public Integer getConnectionRequestTimeout() {
return connectionRequestTimeout;
}

public Integer getSocketTimeout() {
Expand Down Expand Up @@ -359,12 +351,12 @@ private String getResponseBody(CloseableHttpResponse httpResponse) throws
}

public static class Builder {
private HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
private HttpHost proxy;
private UsernamePasswordCredentials proxyCredentials;
private Integer cacheMaxEntries;
private Integer cacheMaxObjectSize;
private Integer connectionRequestTimeout;
private Integer connectTimeout;
private Integer socketTimeout;

public Builder setProxy(HttpHost proxy) {
Expand All @@ -387,13 +379,13 @@ public Builder setCacheMaxObjectSize(Integer cacheMaxObjectSize) {
return this;
}

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

public Builder setConnectTimeout(Integer connectTimeout) {
this.connectTimeout = connectTimeout;
public Builder setConnectionRequestTimeout(Integer connectionRequestTimeout) {
this.connectionRequestTimeout = connectionRequestTimeout;
return this;
}

Expand Down