All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tukeof.common.rest.okhttp.GlobalRequestInterceptor Maven / Gradle / Ivy

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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy