package org.springblade.modules.app.config;

//import feign.RequestInterceptor;
//import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
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;

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

/**
 * <p>
 * 作用描述：
 * </p>
 *
 * @author lq
 * @since 2021/10/10 8:18 下午
 */
@Configuration
@Slf4j
//public class FeignConfiguration implements RequestInterceptor {
public class FeignConfiguration  {

//    @Override
//    public void apply(RequestTemplate template) {
    public void apply() {

        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null) {
            return;
        }
        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
        Enumeration<String> headerNames = request.getHeaderNames();
        if (headerNames != null) {
            while (headerNames.hasMoreElements()) {
                String name = headerNames.nextElement();
                Enumeration<String> values = request.getHeaders(name);
                while (values.hasMoreElements()) {
                    String value = values.nextElement();
                    log.info("name:" + name + ";value:" + value);
//                    template.header(name, value);
                }
            }
        }

    }
}
