Class CorsSupportHelper<Q,R>

Type Parameters:
Q - type of request wrapped by request adapter
R - type of response wrapped by response adapter

public class CorsSupportHelper<Q,R> extends Object
Centralizes internal CORS support common logic for processing requests and preparing responses.

This class is reserved for internal Helidon use. Do not use it from your applications. It might change or vanish at any time.

To serve all masters, several methods here accept adapters for requests and responses. Both of these are minimal and very specific to the needs of CORS support.

  • Method Details

    • normalize

      public static String normalize(String path)
      Trim leading or trailing slashes of a path.
      path - The path.
      Normalized path.
    • parseHeader

      public static Set<String> parseHeader(String header)
      Parse list header value as a set.
      header - Header value as a list.
      Set of header values.
    • parseHeader

      public static Set<String> parseHeader(List<String> headers)
      Parse a list of list of headers as a set.
      headers - Header value as a list, each a potential list.
      Set of header values.
    • isActive

      public boolean isActive()
      Reports whether this helper, due to its set-up, will have a chance of affecting any requests or responses.
      whether the helper might have any effect on requests or responses
    • processRequest

      public Optional<R> processRequest(CorsRequestAdapter<Q> requestAdapter, CorsResponseAdapter<R> responseAdapter)
      Processes a request according to the CORS rules, returning an Optional of the response type if the caller should send the response immediately (such as for a preflight response or an error response to a non-preflight CORS request).

      If the optional is empty, this processor has either:

      • recognized the request as a valid non-preflight CORS request and has set headers in the response adapter, or
      • recognized the request as a non-CORS request entirely.

      In either case of an empty optional return value, the caller should proceed with its own request processing and sends its response at will as long as that processing includes the header settings assigned using the response adapter.

      requestAdapter - abstraction of a request
      responseAdapter - abstraction of a response
      Optional of an error response if the request was an invalid CORS request; Optional.empty() if it was a valid CORS request
    • toString

      public String toString()
      toString in class Object
    • prepareResponse

      public void prepareResponse(CorsRequestAdapter<Q> requestAdapter, CorsResponseAdapter<R> responseAdapter)
      Prepares a response with CORS headers, if the supplied request is in fact a CORS request.
      requestAdapter - abstraction of a request
      responseAdapter - abstraction of a response
    • aggregator

      public Aggregator aggregator()
      Aggregator that combines configuration and provides information based on request.