com.icthh.xm.commons.permission.utils.RequestHeaderUtils Maven / Gradle / Ivy
The newest version!
package com.icthh.xm.commons.permission.utils;
import java.util.Optional;
import lombok.experimental.UtilityClass;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@UtilityClass
public class RequestHeaderUtils {
public static String getRequestHeader(String headerName) {
return Optional.ofNullable(RequestContextHolder.getRequestAttributes())
.filter(ServletRequestAttributes.class::isInstance)
.map(ServletRequestAttributes.class::cast)
.map(ServletRequestAttributes::getRequest)
.map(request -> request.getHeader(headerName))
.orElse(null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy