Interface CorsHandlerHelper
- All Known Implementing Classes:
CorsHandlerHelperImpl
public interface CorsHandlerHelper
Service that provides useful methods for
CorsHandler implementations.- Since:
- 5.8.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the Access-Control-Allow-Credentials HTTP header.static final StringName of the Access-Control-Allow-Headers HTTP header.static final StringName of the Access-Control-Allow-Methods HTTP header.static final StringName of the Access-Control-Allow-Origin HTTP header.static final StringName of the Access-Control-Expose-Headers HTTP header.static final StringName of the Access-Control-Max-Age HTTP header.static final StringOPTIONS HTTP method name.static final StringName of the Origin HTTP header.static final StringThe CORS Origin wildcard.static final StringName of the Access-Control-Request-Headers HTTP header.static final StringName of the Vary HTTP header. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddValueToVaryHeader(javax.servlet.http.HttpServletResponse response, String value) Adds a value to the Vary HTTP header.voidconfigureAllowedHeaders(javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request) Conditionally the Access-Control-Request-Headers HTTP header.voidconfigureCredentials(javax.servlet.http.HttpServletResponse response) Conditionally sets the Access-Control-Allow-Credentials HTTP header.voidconfigureExposeHeaders(javax.servlet.http.HttpServletResponse response) Conditionally sets the Access-Control-Expose-Headers HTTP header.voidconfigureMaxAge(javax.servlet.http.HttpServletResponse response) Conditionally sets the Access-Control-Max-Age HTTP header.voidconfigureMethods(javax.servlet.http.HttpServletResponse response) Conditionally sets the Access-Control-Allow-Methods HTTP header in responses to preflight CORS requests.voidconfigureOrigin(javax.servlet.http.HttpServletResponse response, String value) Sets the Access-Control-Allow-Origin HTTP header with a given value.getAllowedOrigin(javax.servlet.http.HttpServletRequest request) Returns the origin of this requests, if it's allowed.getOrigin(javax.servlet.http.HttpServletRequest request) Returns the value of the Origin HTTP header.getPath(javax.servlet.http.HttpServletRequest request) Returns the requested URL path, using the same logic asRequest.getPath().booleanisPreflight(javax.servlet.http.HttpServletRequest request) Tells whether this request is a CORS preflight one (i.e.
-
Field Details
-
ORIGIN_HEADER
Name of the Origin HTTP header.- See Also:
-
ALLOW_ORIGIN_HEADER
Name of the Access-Control-Allow-Origin HTTP header.- See Also:
-
ALLOW_CREDENTIALS_HEADER
Name of the Access-Control-Allow-Credentials HTTP header.- See Also:
-
ALLOW_METHODS_HEADER
Name of the Access-Control-Allow-Methods HTTP header.- See Also:
-
REQUEST_HEADERS_HEADER
Name of the Access-Control-Request-Headers HTTP header.- See Also:
-
ALLOW_HEADERS_HEADER
Name of the Access-Control-Allow-Headers HTTP header.- See Also:
-
EXPOSE_HEADERS_HEADER
Name of the Access-Control-Expose-Headers HTTP header.- See Also:
-
MAX_AGE_HEADER
Name of the Access-Control-Max-Age HTTP header.- See Also:
-
VARY_HEADER
Name of the Vary HTTP header.- See Also:
-
OPTIONS_METHOD
OPTIONS HTTP method name.- See Also:
-
ORIGIN_WILDCARD
The CORS Origin wildcard.- See Also:
-
-
Method Details
-
getPath
Returns the requested URL path, using the same logic asRequest.getPath().- Parameters:
request- anHttpServletRequest.- Returns:
- a
Stringwith the path.
-
getOrigin
Returns the value of the Origin HTTP header.- Parameters:
request- anHttpServletRequest.- Returns:
- an
Optionalwrapping the Origin HTTP header value.
-
isPreflight
Tells whether this request is a CORS preflight one (i.e. HTTP method OPTION and non-empty Origin HTTP header).- Parameters:
request- anHttpServletRequest.- Returns:
trueif it's a preflight request,falseotherwise.
-
getAllowedOrigin
Returns the origin of this requests, if it's allowed.- Parameters:
request- anHttpServletRequest.- Returns:
- an
Optionalwrapping the allowed origin. - See Also:
-
configureOrigin
Sets the Access-Control-Allow-Origin HTTP header with a given value.- Parameters:
value- a String.response- anHttpServletResponseinstance.- See Also:
-
configureCredentials
Conditionally sets the Access-Control-Allow-Credentials HTTP header. Out-of-the-box, this is done based on theTapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALSsymbol.- Parameters:
response- anHttpServletResponse.- See Also:
-
configureMethods
Conditionally sets the Access-Control-Allow-Methods HTTP header in responses to preflight CORS requests. Out-of-the-box, the value comes fromTapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALSsymbol and the header is only set if the value isn't empty.- Parameters:
response- anHttpServletResponse.- See Also:
-
configureAllowedHeaders
void configureAllowedHeaders(javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request) Conditionally the Access-Control-Request-Headers HTTP header. Out-of-the-box, the value comes fromTapestryHttpSymbolConstants.CORS_ALLOWED_HEADERSsymbol if not empty. Otherwise, it comes from the value of the same HTTP header from the request, also if not empty. Otherwise, the header isn't set.- Parameters:
response- anHttpServletResponse.request- anHttpServletRequest.- See Also:
-
configureExposeHeaders
Conditionally sets the Access-Control-Expose-Headers HTTP header. Out-of-the-box, the value comes fromTapestryHttpSymbolConstants.CORS_EXPOSE_HEADERSsymbol, if not empty. Otherwise, the header isn't set.- Parameters:
response- anHttpServletResponse.- See Also:
-
configureMaxAge
Conditionally sets the Access-Control-Max-Age HTTP header. Out-of-the-box, the value comes fromTapestryHttpSymbolConstants.CORS_MAX_AGEsymbol, if not empty. Otherwise, the header isn't set.- Parameters:
response- anHttpServletResponse.- See Also:
-
addValueToVaryHeader
Adds a value to the Vary HTTP header.- Parameters:
response- anHttpServletResponseinstance.value- the value to be added.
-