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
33 changes: 25 additions & 8 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 All @@ -38,6 +39,7 @@
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;
Expand Down Expand Up @@ -75,14 +77,19 @@
);
}

ConnectionConfig connectionConfig = ConnectionConfig
.custom()
.setConnectTimeout(builder.connectTimeout != null
? Timeout.ofMilliseconds(builder.connectTimeout)
: ConnectionConfig.DEFAULT.getConnectTimeout())
.build();
BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
connectionManager.setConnectionConfig(connectionConfig);
if (builder.connectionManager != null) {
this.connectionManager = builder.connectionManager;

Check warning on line 81 in src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java#L81

Added line #L81 was not covered by tests
} else {
BasicHttpClientConnectionManager basicHttpClientConnectionManager = new BasicHttpClientConnectionManager();
basicHttpClientConnectionManager.setConnectionConfig(ConnectionConfig
.custom()
.setConnectTimeout(connectTimeout != null ?
Timeout.ofMilliseconds(connectTimeout) :

Check warning on line 87 in src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java#L87

Added line #L87 was not covered by tests
ConnectionConfig.DEFAULT.getConnectTimeout())
.build());
this.connectionManager = basicHttpClientConnectionManager;
}

RequestConfig requestConfig = RequestConfig
.custom()
.setCookieSpec(StandardCookieSpec.STRICT)
Expand Down Expand Up @@ -128,6 +135,10 @@
}
}

public HttpClientConnectionManager getConnectionManager() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConnectionManager is no longer necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have those getters for all class variables right now, like getProxy, ... which we don't use in our code base either, so I just added this as well.

return connectionManager;

Check warning on line 139 in src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java#L139

Added line #L139 was not covered by tests
}

public HttpHost getProxy() {
return proxy;
}
Expand Down Expand Up @@ -359,6 +370,7 @@
}

public static class Builder {
private HttpClientConnectionManager connectionManager;
private HttpHost proxy;
private UsernamePasswordCredentials proxyCredentials;
private Integer cacheMaxEntries;
Expand All @@ -367,6 +379,11 @@
private Integer connectTimeout;
private Integer socketTimeout;

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

Check warning on line 384 in src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java#L383-L384

Added lines #L383 - L384 were not covered by tests
}

public Builder setProxy(HttpHost proxy) {
this.proxy = proxy;
return this;
Expand Down
Loading