package com.sf.common.utils.http;

import com.sf.common.utils.StringUtils;
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;

public class RequestUtils {

    public static String getHeader(String code){
        HttpServletRequest request = null;
        try {
            RequestAttributes requestAttributes1 = RequestContextHolder.getRequestAttributes();
            request = ((ServletRequestAttributes) requestAttributes1).getRequest();
        } catch (Exception e) {
            throw new SecurityException("获取header中获取appCode信息");
        }
        if(StringUtils.isBlank(request.getHeader(code))){
            throw new SecurityException("参数异常appCode为空");
        }
        return request.getHeader(code);
    }
}
