package com.rongwei.bscommon.sys.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author shangmi
 * @title FeignConfigration
 * @date 2023/12/6 11:54
 * @description feign配置文件
 */
@Configuration
public class FeignConfiguration implements RequestInterceptor {
    private final static Logger log = LoggerFactory.getLogger(FeignConfiguration.class);
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if(null == attributes){
            return;
        }
        String authorization = attributes.getRequest().getHeader("Authorization");
        log.info("Authorization:{}",authorization);
        requestTemplate.header("Authorization",authorization);
    }
}
