Class Aggregator

java.lang.Object
io.helidon.cors.Aggregator

public class Aggregator extends Object
Collects CORS set-up information from various sources and looks up the relevant CORS information given a request's path and HTTP method.

The caller builds the cross-config information over multiple invocations of the builder methods. The behavior is that of a List: when matching against a request's path and method, the aggregator checks the path matchers in the order they were added to the aggregator, whether by Aggregator.Builder.mappedConfig(io.helidon.common.config.Config) or Aggregator.Builder.addCrossOrigin(java.lang.String, io.helidon.cors.CrossOriginConfig) or the CorsSetter methods.

The CorsSetter methods affect a distinct "pathless" entry. Those methods have no explicit path, so we record their settings in an entry with path expression "{+}" which matches everything. The first time the caller invokes a CorsSetter method, the aggregator creates this distinct entry and adds it to the list, thus (as with any other entry) determining the order, relative to other entries, with which it will be checked.

  • Field Details

    • PATHLESS_KEY

      public static final String PATHLESS_KEY
      Key value for the map corresponding to the cross-origin config managed by the CorsSetter methods.
      See Also:
  • Method Details

    • isActive

      public boolean isActive()
      Reports whether the sources of CORS information have left CORS active or not. This is a combination of any explicit setting of enabled with whether any CrossOriginConfig instances were added -- either explicitly or using config. If not, then the aggregator will never find a match among the matchables so it is as good as inactive.
      Returns:
      if this aggregator will contribute to CORS processing
    • isEnabled

      public boolean isEnabled()
      Reports whether the aggregator (and, by implication, the config for CORS) is enabled or not.
      Returns:
      if CORS is enabled
    • lookupCrossOrigin

      public Optional<CrossOriginConfig> lookupCrossOrigin(String path, String method, Supplier<Optional<CrossOriginConfig>> secondaryLookup)
      Looks for a matching CORS config entry for the specified path among the provided CORS configuration information, returning an Optional of the matching CrossOrigin instance for the path, if any.
      Parameters:
      path - the unnormalized request path to check
      method - HTTP method
      secondaryLookup - Supplier for CrossOrigin used if none found in config
      Returns:
      Optional<CrossOriginConfig> for the matching config, or an empty Optional if none matched
    • toString

      public String toString()
      Overrides:
      toString in class Object