Top Description Fields Constructors Methods
org.springframework.web.reactive.resource

public Class PathResourceResolver

extends AbstractResourceResolver
Class Inheritance
Imports
java.io.IOException, java.net.URLDecoder, java.nio.charset.StandardCharsets, java.util.Arrays, .List, reactor.core.publisher.Flux, .Mono, org.springframework.core.io.ClassPathResource, .Resource, .UrlResource, org.springframework.core.log.LogFormatUtils, org.springframework.lang.Nullable, org.springframework.util.StringUtils, org.springframework.web.server.ServerWebExchange, org.springframework.web.util.UriUtils

A simple ResourceResolver that tries to find a resource under the given locations matching to the request path.

This resolver does not delegate to the ResourceResolverChain and is expected to be configured at the end in a chain of resolvers.

Authors
Rossen Stoyanchev, Sam Brannen
Since
5.0

Field Summary

Modifier and TypeField and Description
private Resource[]
Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

"true" if resource is in a valid location, "false" otherwise
checkResource
(Resource
the resource to check
resource
,
Resource
the location relative to which the resource was found
location
)

Perform additional checks on a resolved resource beyond checking whether the resource exists and is readable.

public Resource[]
private Mono<Resource>
getResource(String resourcePath, List<? extends Resource> locations)

protected Mono<Resource>

Returns:

the resource, or empty Mono if none found
getResource
(String
the path to the resource
resourcePath
,
Resource
the location to check
location
)

Find the resource under the given location.

private boolean
private boolean
protected Mono<Resource>
protected Mono<String>
public void
setAllowedLocations(Resource...
the list of allowed locations
locations
)

By default, when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found.

Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
resolveResourceresolveUrlPath

Field Detail

allowedLocationsback to summary
private Resource[] allowedLocations
Annotations
@Nullable

Constructor Detail

PathResourceResolverback to summary
public PathResourceResolver()

Method Detail

checkResourceback to summary
protected boolean checkResource(Resource resource, Resource location) throws IOException

Perform additional checks on a resolved resource beyond checking whether the resource exists and is readable. The default implementation also verifies the resource is either under the location relative to which it was found or is under one of the allowed locations.

Parameters
resource:Resource

the resource to check

location:Resource

the location relative to which the resource was found

Returns:boolean

"true" if resource is in a valid location, "false" otherwise

getAllowedLocationsback to summary
public Resource[] getAllowedLocations()
Annotations
@Nullable
getResourceback to summary
private Mono<Resource> getResource(String resourcePath, List<? extends Resource> locations)
getResourceback to summary
protected Mono<Resource> getResource(String resourcePath, Resource location)

Find the resource under the given location.

The default implementation checks if there is a readable Resource for the given path relative to the location.

Parameters
resourcePath:String

the path to the resource

location:Resource

the location to check

Returns:Mono<Resource>

the resource, or empty Mono if none found

isInvalidEncodedPathback to summary
private boolean isInvalidEncodedPath(String resourcePath)
isResourceUnderLocationback to summary
private boolean isResourceUnderLocation(Resource resource, Resource location) throws IOException
resolveResourceInternalback to summary
protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveResourceInternal.

Annotations
@Override
resolveUrlPathInternalback to summary
protected Mono<String> resolveUrlPathInternal(String path, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveUrlPathInternal.

Annotations
@Override
setAllowedLocationsback to summary
public void setAllowedLocations(Resource... locations)

By default, when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found. However sometimes that may not be the case, e.g. when CssLinkResourceTransformer resolves public URLs of links it contains, the CSS file is the location and the resources being resolved are css files, images, fonts and others located in adjacent or parent directories.

This property allows configuring a complete list of locations under which resources must be so that if a resource is not under the location relative to which it was found, this list may be checked as well.

By default ResourceWebHandler initializes this property to match its list of locations.

Parameters
locations:Resource[]

the list of allowed locations