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
14 changes: 12 additions & 2 deletions src/main/java/sirius/kernel/commons/Outcall.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.CookieManager;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URI;
Expand Down Expand Up @@ -110,6 +111,14 @@ public class Outcall {

private static final Pattern CHARSET_PATTERN = Pattern.compile("(?i)\\bcharset=\\s*\"?([^\\s;\"]*)");

/**
* Provides a constant for {@link #modifyClient(String)} to signal that the generated client must not be re-used or
* cached.
*/
public static final String CLIENT_SELECTOR_NO_CACHE = null;

private static final String DEFAULT_CLIENT_SELECTOR = "_default_";

/**
* Keeps track of hosts for which we ran into a connect-timeout.
* <p>
Expand Down Expand Up @@ -149,7 +158,6 @@ public class Outcall {
private static final Map<String, HttpClient> cachedHttpClients = new ConcurrentHashMap<>();

private static final int MAX_REDIRECTS = 5;
private static final String DEFAULT_CLIENT_SELECTOR = "_default_";

private String clientSelector = DEFAULT_CLIENT_SELECTOR;
private HttpClient client;
Expand Down Expand Up @@ -220,7 +228,9 @@ public HttpClient.Builder modifyClient() {
* across multiple requests.
*
* @param clientSelector a unique string for all occasions where the builder is customized the same way and thus
* the cached client can be re-used once it has been created
* the cached client can be re-used once it has been created.
* Use {@link #CLIENT_SELECTOR_NO_CACHE} to signal that the created client should not be
* re-used (e.g. if a {@link java.net.CookieManager} is used).
* @return the underlying {@link HttpClient.Builder}
*/
public HttpClient.Builder modifyClient(@Nullable String clientSelector) {
Expand Down