package io.renren.modules.kubesphere.interceptor;

import io.renren.modules.kubesphere.config.KubeSphereConfig;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;

/**
 * @author chenrj
 * @email 1412736935@qq.com
 * @since 2021/8/1
 */
public class KubeSphereTokenInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
        httpRequest.getHeaders().add("Accept", KubeSphereConfig.ACCEPT);
        httpRequest.getHeaders().add("Origin", KubeSphereConfig.ORIGIN);
        httpRequest.getHeaders().add("User-Agent", KubeSphereConfig.UA);
//        httpRequest.getHeaders().add("refer",KubeSphereConfig.REFERER);
        httpRequest.getHeaders().add("Authorization", String.format("Bearer %s", KubeSphereTokenManger.get().getToken()));
        httpRequest.getHeaders().add("Content-Type", "application/json");
//        httpRequest.getHeaders().add("Host","192.168.31.231:30880");
        httpRequest.getHeaders().add("Accept-Encoding", "gzip, deflate, br");
        httpRequest.getHeaders().add("Connection", "keep-alive");
        return clientHttpRequestExecution.execute(httpRequest, bytes);

    }
}
