package com.wisewoods.base.net;

import com.wisewoods.base.utils.$;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class HttpInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        if ($.spNoNull("jwtToken")) {
            request = request.newBuilder()
                    .addHeader("Accept-Encoding", "identity")
                    .addHeader("authorization", "Bearer " + $.getSp("jwtToken"))
                    .build();
        } else {
            request = request.newBuilder()
                    .addHeader("Accept-Encoding", "identity")
                    .build();
        }
        return chain.proceed(request);
    }
}
