Class CorsUtil


  • public class CorsUtil
    extends Object
    Utility class for CORS handling.
    Author:
    Emmanuel Hugonnet (c) 2014 Red Hat, inc.
    • Constructor Detail

      • CorsUtil

        public CorsUtil()
    • Method Detail

      • isCoreRequest

        public static boolean isCoreRequest​(io.undertow.util.HeaderMap headers)
      • matchOrigin

        public static String matchOrigin​(io.undertow.server.HttpServerExchange exchange,
                                         Collection<String> allowedOrigins)
                                  throws Exception
        Match the Origin header with the allowed origins. If it doesn't match then a 403 response code is set on the response and it returns null.
        Parameters:
        exchange - the current HttpExchange.
        allowedOrigins - list of sanitized allowed origins.
        Returns:
        the first matching origin, null otherwise.
        Throws:
        Exception
      • defaultOrigin

        public static String defaultOrigin​(io.undertow.server.HttpServerExchange exchange)
        Determine the default origin, to allow for local access.
        Parameters:
        exchange - the current HttpExchange.
        Returns:
        the default origin (aka current server).
      • sanitizeDefaultPort

        public static String sanitizeDefaultPort​(String url)
        Removes the port from a URL if this port is the default one for the URL's scheme.
        Parameters:
        url - the url to be sanitized.
        Returns:
        the sanitized url.
      • isPreflightedRequest

        public static boolean isPreflightedRequest​(io.undertow.server.HttpServerExchange exchange)