Package org.apache.tapestry5.http.internal.services

# Class CorsHandlerHelperImpl

java.lang.Object
org.apache.tapestry5.http.internal.services.CorsHandlerHelperImpl

All Implemented Interfaces:
  `CorsHandlerHelper`

public class CorsHandlerHelperImpl extends Object implements CorsHandlerHelper
Default `CorsHandlerHelper` implementation.

Since:
  5.8.2
See Also:
  - `CorsHandler`
  - `TapestryHttpSymbolConstants.CORS_ENABLED`
  - `TapestryHttpSymbolConstants.CORS_ALLOWED_ORIGINS`

- ## Field Summary

  ### Fields inherited from interface org.apache.tapestry5.http.services.CorsHandlerHelper

  `ALLOW_CREDENTIALS_HEADER, ALLOW_HEADERS_HEADER, ALLOW_METHODS_HEADER, ALLOW_ORIGIN_HEADER, EXPOSE_HEADERS_HEADER, MAX_AGE_HEADER, OPTIONS_METHOD, ORIGIN_HEADER, ORIGIN_WILDCARD, REQUEST_HEADERS_HEADER, VARY_HEADER`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CorsHandlerHelperImpl(String allowedOrigins, boolean allowCredentials, String allowMethods, String allowedHeaders, String exposeHeaders, String maxAge)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `configureAllowedHeaders(javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request)`
  Conditionally the Access-Control-Request-Headers HTTP header.
  `void`
  `configureCredentials(javax.servlet.http.HttpServletResponse response)`
  Conditionally sets the Access-Control-Allow-Credentials HTTP header.
  `void`
  `configureExposeHeaders(javax.servlet.http.HttpServletResponse response)`
  Conditionally sets the Access-Control-Expose-Headers HTTP header.
  `void`
  `configureMaxAge(javax.servlet.http.HttpServletResponse response)`
  Conditionally sets the Access-Control-Max-Age HTTP header.
  `void`
  `configureMethods(javax.servlet.http.HttpServletResponse response)`
  Conditionally sets the Access-Control-Allow-Methods HTTP header in responses to preflight CORS requests.
  `void`
  `configureOrigin(javax.servlet.http.HttpServletResponse response, String value)`
  Sets the Access-Control-Allow-Origin HTTP header with a given value.
  `Optional<String>`
  `getAllowedOrigin(javax.servlet.http.HttpServletRequest request)`
  Returns the origin of this requests, if it's allowed.
  `Optional<String>`
  `getOrigin(javax.servlet.http.HttpServletRequest request)`
  Returns the value of the Origin HTTP header.
  `String`
  `getPath(javax.servlet.http.HttpServletRequest request)`
  Returns the requested URL path, using the same logic as `Request.getPath()`.
  `boolean`
  `isPreflight(javax.servlet.http.HttpServletRequest request)`
  Tells whether this request is a CORS preflight one (i.e.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.tapestry5.http.services.CorsHandlerHelper

  `addValueToVaryHeader`

- ## Constructor Details

  - ### CorsHandlerHelperImpl

    public CorsHandlerHelperImpl(@Symbol("tapestry.cors-allowed-origins") String allowedOrigins, @Symbol("tapestry.cors-allow-credentials") boolean allowCredentials, @Symbol("tapestry.cors-allow-methods") String allowMethods, @Symbol("tapestry.cors-allowed-headers") String allowedHeaders, @Symbol("tapestry.cors-expose-headers") String exposeHeaders, @Symbol("tapestry.cors-max-age") String maxAge)

- ## Method Details

  - ### getPath

    public String getPath(javax.servlet.http.HttpServletRequest request)
    Description copied from interface: `CorsHandlerHelper`
    Returns the requested URL path, using the same logic as `Request.getPath()`.
    Specified by:
      `getPath` in interface `CorsHandlerHelper`
    Parameters:
      `request` - an `HttpServletRequest`.
    Returns:
      a `String` with the path.

  - ### getAllowedOrigin

    public Optional<String> getAllowedOrigin(javax.servlet.http.HttpServletRequest request)
    Description copied from interface: `CorsHandlerHelper`
    Returns the origin of this requests, if it's allowed.
    Specified by:
      `getAllowedOrigin` in interface `CorsHandlerHelper`
    Parameters:
      `request` - an `HttpServletRequest`.
    Returns:
      an `Optional` wrapping the allowed origin.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_ALLOWED_ORIGINS`

  - ### getOrigin

    public Optional<String> getOrigin(javax.servlet.http.HttpServletRequest request)
    Description copied from interface: `CorsHandlerHelper`
    Returns the value of the Origin HTTP header.
    Specified by:
      `getOrigin` in interface `CorsHandlerHelper`
    Parameters:
      `request` - an `HttpServletRequest`.
    Returns:
      an `Optional` wrapping the Origin HTTP header value.

  - ### isPreflight

    public boolean isPreflight(javax.servlet.http.HttpServletRequest request)
    Description copied from interface: `CorsHandlerHelper`
    Tells whether this request is a CORS preflight one (i.e. HTTP method OPTION and non-empty Origin HTTP header).
    Specified by:
      `isPreflight` in interface `CorsHandlerHelper`
    Parameters:
      `request` - an `HttpServletRequest`.
    Returns:
      `true` if it's a preflight request, `false` otherwise.

  - ### configureOrigin

    public void configureOrigin(javax.servlet.http.HttpServletResponse response, String value)
    Description copied from interface: `CorsHandlerHelper`
    Sets the Access-Control-Allow-Origin HTTP header with a given value.
    Specified by:
      `configureOrigin` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse` instance.
      `value` - a String.
    See Also:
      - `CorsHandlerHelper.ALLOW_ORIGIN_HEADER`

  - ### configureCredentials

    public void configureCredentials(javax.servlet.http.HttpServletResponse response)
    Description copied from interface: `CorsHandlerHelper`
    Conditionally sets the Access-Control-Allow-Credentials HTTP header. Out-of-the-box, this is done based on the `TapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALS` symbol.
    Specified by:
      `configureCredentials` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse`.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALS`

  - ### configureMethods

    public void configureMethods(javax.servlet.http.HttpServletResponse response)
    Description copied from interface: `CorsHandlerHelper`
    Conditionally sets the Access-Control-Allow-Methods HTTP header in responses to preflight CORS requests. Out-of-the-box, the value comes from `TapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALS` symbol and the header is only set if the value isn't empty.
    Specified by:
      `configureMethods` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse`.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_ALLOW_CREDENTIALS`

  - ### configureAllowedHeaders

    public void configureAllowedHeaders(javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request)
    Description copied from interface: `CorsHandlerHelper`
    Conditionally the Access-Control-Request-Headers HTTP header. Out-of-the-box, the value comes from `TapestryHttpSymbolConstants.CORS_ALLOWED_HEADERS` symbol 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.
    Specified by:
      `configureAllowedHeaders` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse`.
      `request` - an `HttpServletRequest`.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_ALLOWED_HEADERS`

  - ### configureExposeHeaders

    public void configureExposeHeaders(javax.servlet.http.HttpServletResponse response)
    Description copied from interface: `CorsHandlerHelper`
    Conditionally sets the Access-Control-Expose-Headers HTTP header. Out-of-the-box, the value comes from `TapestryHttpSymbolConstants.CORS_EXPOSE_HEADERS` symbol, if not empty. Otherwise, the header isn't set.
    Specified by:
      `configureExposeHeaders` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse`.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_EXPOSE_HEADERS`

  - ### configureMaxAge

    public void configureMaxAge(javax.servlet.http.HttpServletResponse response)
    Description copied from interface: `CorsHandlerHelper`
    Conditionally sets the Access-Control-Max-Age HTTP header. Out-of-the-box, the value comes from `TapestryHttpSymbolConstants.CORS_MAX_AGE` symbol, if not empty. Otherwise, the header isn't set.
    Specified by:
      `configureMaxAge` in interface `CorsHandlerHelper`
    Parameters:
      `response` - an `HttpServletResponse`.
    See Also:
      - `TapestryHttpSymbolConstants.CORS_MAX_AGE`