org.springframework.web.util.HttpClientUtil Maven / Gradle / Ivy
The newest version!
package org.springframework.web.util;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
public abstract class HttpClientUtil {
private static final Set DISALLOWED_HEADERS_SET;
static {
Set treeSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
treeSet.addAll(
Set.of("connection", "content-length", "date", "expect", "from", "host", "upgrade", "via", "warning"));
DISALLOWED_HEADERS_SET = Collections.unmodifiableSet(treeSet);
}
private static final Predicate ALLOWED_HEADERS = (header) -> !DISALLOWED_HEADERS_SET.contains(header);
/**
* Judge whether the header is allowed to be passed. The error will be checked directly under Java 11
.
*
* @param headerName headerName
* @return Allow or not
*/
public static boolean allowed(String headerName) {
return ALLOWED_HEADERS.test(headerName);
}
private HttpClientUtil() {
throw new IllegalStateException("Can't instantiate a utility class");
}
}