HttpRequestHandler that serves static resources in an optimized way
according to the guidelines of Page Speed, YSlow, etc.
The "locations" property takes a list of Spring
Resource locations from which static resources are allowed to
be served by this handler. Resources could be served from a classpath location,
e.g. "classpath:/META-INF/public-web-resources/", allowing convenient packaging
and serving of resources such as .js, .css, and others in jar files.
This request handler may also be configured with a
resourceTransformer chains to support
arbitrary resolution and transformation of resources being served. By default a
PathResourceResolver simply finds resources based on the configured
"locations". An application can configure additional resolvers and
transformers such as the VersionResourceResolver which can resolve
and prepare URLs for resources with a version in the URL.
This handler also properly evaluates the Last-Modified header (if
present) so that a 304 status code will be returned as appropriate,
avoiding unnecessary overhead for resources that are already cached by the
java.lang.Exception - in the event of misconfiguration (such as failure to set an
essential property) or if initialization fails for any other reason
protected void initAllowedLocations()
Look for a PathResourceResolver among the configured resource
resolvers and set its allowedLocations property (if empty) to
match the locations configured on this class.
public reactor.core.publisher.Mono<java.lang.Void> handle(ServerWebExchange exchange)
Processes a resource request.
Checks for the existence of the requested resource in the configured list of locations.
If the resource does not exist, a 404 response will be returned to the client.
If the resource exists, the request will be checked for the presence of the
Last-Modified header, and its value will be compared against the last-modified
timestamp of the given resource, returning a 304 status code if the
Last-Modified value is greater. If the resource is newer than the
Last-Modified value, or the header is not present, the content resource
of the resource will be written to the response with caching headers
set to expire one year in the future.