com.algolia.internal.interceptors.HeaderInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch Show documentation
Show all versions of algoliasearch Show documentation
Java client for Algolia Search API
The newest version!
package com.algolia.internal.interceptors;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import javax.annotation.Nonnull;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.Response;
public final class HeaderInterceptor implements Interceptor {
private final Map headers;
public HeaderInterceptor(Map headers) {
this.headers = Collections.unmodifiableMap(headers);
}
@Nonnull
@Override
public Response intercept(Chain chain) throws IOException {
okhttp3.Request request = chain.request();
okhttp3.Request.Builder builder = request.newBuilder();
Headers requestHeaders = request.headers();
for (Map.Entry header : headers.entrySet()) {
String key = header.getKey();
if (requestHeaders.get(key) != null) {
builder.header(key, header.getValue());
}
}
okhttp3.Request newRequest = builder.build();
return chain.proceed(newRequest);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy