/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.webapi.remote.interceptor;

import com.codvision.webapi.common.RequestUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * 基础请求拦截
 *
 * @author lingee
 * @date 2023/8/2
 */
@Slf4j
public class BaseRequestInterceptor implements RequestInterceptor {

    /**
     * Authorization方式认证
     */
    private static final String HEADER_AUTHORIZATION = "Authorization";

    @Override
    public void apply(RequestTemplate requestTemplate) {
        log.info("请求路径为：{}", requestTemplate.path());

        HttpServletRequest request = Objects.requireNonNull(RequestUtil.getRequest());

        String token = request.getHeader(HEADER_AUTHORIZATION);
        log.info("Authorization值为：{}", token);

        requestTemplate.header(HEADER_AUTHORIZATION, token);
    }
}
