rk
昨天 4a8ff39b0fab0627ef8f7459587d514cc01c3676
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.doumee.lib_coremodel.http.interceptor;
 
import java.io.IOException;
import java.util.Map;
import java.util.Set;
 
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
 
/**
 * Created by goldze on 2017/5/10.
 */
public class BaseInterceptor implements Interceptor {
    private Map<String, String> headers;
 
    public BaseInterceptor(Map<String, String> headers) {
        this.headers = headers;
    }
 
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request()
                .newBuilder();
        if (headers != null && headers.size() > 0) {
            Set<String> keys = headers.keySet();
            for (String headerKey : keys) {
                builder.addHeader(headerKey, headers.get(headerKey)).build();
            }
        }
        //请求信息
        return chain.proceed(builder.build());
    }
}