Skip to content

Commit

Permalink
Merge pull request #147 from Apicurio/do-not-share-headers
Browse files Browse the repository at this point in the history
Do not share headers between client instances
  • Loading branch information
carlesarnal authored May 30, 2023
2 parents 59a99c9 + d2153e1 commit d87b066
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
public class JdkHttpClient implements ApicurioHttpClient {

public static final String INVALID_EMPTY_HTTP_KEY = "";
private HttpClient client;
private final HttpClient client;
private final String endpoint;
private final Auth auth;
private final RestClientErrorHandler errorHandler;

private static final Map<String, String> DEFAULT_HEADERS = new HashMap<>();
private final Map<String, String> DEFAULT_HEADERS = new HashMap<>();
private static final ThreadLocal<Map<String, String>> requestHeaders = ThreadLocal.withInitial(Collections::emptyMap);

public JdkHttpClient(String endpoint, Map<String, Object> configs, Auth auth, RestClientErrorHandler errorHandler) {
Expand All @@ -69,15 +69,15 @@ public JdkHttpClient(String endpoint, Map<String, Object> configs, Auth auth, Re
this.errorHandler = errorHandler;
}

private static HttpClient.Builder handleConfiguration(Map<String, Object> configs) {
private HttpClient.Builder handleConfiguration(Map<String, Object> configs) {
HttpClient.Builder clientBuilder = HttpClient.newBuilder();
clientBuilder.version(HttpClient.Version.HTTP_1_1);
addHeaders(configs);
clientBuilder = addSSL(clientBuilder, configs);
return clientBuilder;
}

private static void addHeaders(Map<String, Object> configs) {
private void addHeaders(Map<String, Object> configs) {

Map<String, String> requestHeaders = configs.entrySet().stream()
.filter(map -> map.getKey().startsWith(ApicurioClientConfig.APICURIO_REQUEST_HEADERS_PREFIX))
Expand All @@ -86,7 +86,7 @@ private static void addHeaders(Map<String, Object> configs) {

if (!requestHeaders.isEmpty()) {
requestHeaders.remove(INVALID_EMPTY_HTTP_KEY);
requestHeaders.forEach(DEFAULT_HEADERS::put);
DEFAULT_HEADERS.putAll(requestHeaders);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class VertxHttpClient implements ApicurioHttpClient {
private final String basePath;
private final RestClientErrorHandler errorHandler;

private static final Map<String, String> DEFAULT_HEADERS = new HashMap<>();
private final Map<String, String> DEFAULT_HEADERS = new HashMap<>();
private static final ThreadLocal<Map<String, String>> requestHeaders = ThreadLocal.withInitial(Collections::emptyMap);

public VertxHttpClient(Vertx vertx, String basePath, Map<String, Object> options, Auth auth, RestClientErrorHandler errorHandler) {
Expand Down Expand Up @@ -66,7 +66,7 @@ private WebClientOptions createClientOptions(Map<String, Object> config) {
return options;
}

private static void processConfiguration(Map<String, Object> configs) {
private void processConfiguration(Map<String, Object> configs) {
Map<String, String> requestHeaders = configs.entrySet().stream()
.filter(map -> map.getKey().startsWith(ApicurioClientConfig.APICURIO_REQUEST_HEADERS_PREFIX))
.collect(Collectors.toMap(map -> map.getKey()
Expand Down

0 comments on commit d87b066

Please sign in to comment.