com.tukeof.common.rest.okhttp.GlobalRequestInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-rest Show documentation
Show all versions of common-rest Show documentation
a encapsulated restful java library
The newest version!
package com.tukeof.common.rest.okhttp;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.util.Map;
public class GlobalRequestInterceptor implements Interceptor {
private final Map headers;
public GlobalRequestInterceptor(Map headers) {
this.headers = headers;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request.Builder builder = request.newBuilder();
for (String name : headers.keySet()) {
builder.addHeader(name, headers.get(name));
}
return chain.proceed(builder.build());
}
}