java.lang.Object
io.helidon.cors.CorsSupportHelper<Q,R>
- Type Parameters:
Q
- type of request wrapped by request adapterR
- type of response wrapped by response adapter
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class forCorsSupportHelper
s.static enum
Not for use by developers. CORS-related classification of HTTP requests. -
Method Summary
Modifier and TypeMethodDescriptionAggregator that combines configuration and provides information based on request.boolean
isActive()
Reports whether this helper, due to its set-up, will have a chance of affecting any requests or responses.static String
Trim leading or trailing slashes of a path.parseHeader
(String header) Parse list header value as a set.parseHeader
(List<String> headers) Parse a list of list of headers as a set.void
prepareResponse
(CorsRequestAdapter<Q> requestAdapter, CorsResponseAdapter<R> responseAdapter) Prepares a response with CORS headers, if the supplied request is in fact a CORS request.processRequest
(CorsRequestAdapter<Q> requestAdapter, CorsResponseAdapter<R> responseAdapter) Processes a request according to the CORS rules, returning anOptional
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).toString()
-
Method Details
-
normalize
Trim leading or trailing slashes of a path.- Parameters:
path
- The path.- Returns:
- Normalized path.
-
parseHeader
Parse list header value as a set.- Parameters:
header
- Header value as a list.- Returns:
- Set of header values.
-
parseHeader
Parse a list of list of headers as a set.- Parameters:
headers
- Header value as a list, each a potential list.- Returns:
- 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.- Returns:
- 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 anOptional
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.
- Parameters:
requestAdapter
- abstraction of a requestresponseAdapter
- abstraction of a response- Returns:
- Optional of an error response if the request was an invalid CORS request; Optional.empty() if it was a valid CORS request
-
toString
-
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.- Parameters:
requestAdapter
- abstraction of a requestresponseAdapter
- abstraction of a response
-
aggregator
Aggregator that combines configuration and provides information based on request.- Returns:
- aggregator
-