org.springframework.web.reactive.resource

## Class EncodedResourceResolver

- java.lang.Object
- - org.springframework.web.reactive.resource.AbstractResourceResolver
  - - org.springframework.web.reactive.resource.EncodedResourceResolver

All Implemented Interfaces:
  ResourceResolver

    public class EncodedResourceResolver
    extends AbstractResourceResolver

Resolver that delegates to the chain, and if a resource is found, it then attempts to find an encoded (e.g. gzip, brotli) variant that is acceptable based on the "Accept-Encoding" request header.

The list of supported `contentCodings` can be configured, in order of preference, and each coding must be associated with `extensions`.

Note that this resolver must be ordered ahead of a `VersionResourceResolver` with a content-based, version strategy to ensure the version calculation is not impacted by the encoding.

Since:
  5.1
Author:
  Rossen Stoyanchev

### Field Summary

Fields
`static List<String>` `DEFAULT_CODINGS` The default content codings.

### Fields inherited from class org.springframework.web.reactive.resource.AbstractResourceResolver

`logger`

### Constructor Summary

Constructors
Constructor and Description
`EncodedResourceResolver()`

### Method Summary

All Methods Instance Methods Concrete Methods
`List<String>` `getContentCodings()` Return a read-only list with the supported content codings.
`Map<String,String>` `getExtensions()` Return a read-only map with coding-to-extension mappings.
`void` `registerExtension(String coding, String extension)` Java config friendly alternative to `setExtensions(Map)`.
`protected reactor.core.publisher.Mono<org.springframework.core.io.Resource>` `resolveResourceInternal(org.springframework.web.server.ServerWebExchange exchange, String requestPath, List<? extends org.springframework.core.io.Resource> locations, ResourceResolverChain chain)`
`protected reactor.core.publisher.Mono<String>` `resolveUrlPathInternal(String resourceUrlPath, List<? extends org.springframework.core.io.Resource> locations, ResourceResolverChain chain)`
`void` `setContentCodings(List<String> codings)` Configure the supported content codings in order of preference.
`void` `setExtensions(Map<String,String> extensions)` Configure mappings from content codings to file extensions.

### Methods inherited from class org.springframework.web.reactive.resource.AbstractResourceResolver

`resolveResource, resolveUrlPath`

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

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

### Field Detail

#### DEFAULT_CODINGS

    public static final List<String> DEFAULT_CODINGS

The default content codings.

### Constructor Detail

#### EncodedResourceResolver

    public EncodedResourceResolver()

### Method Detail

#### setContentCodings

    public void setContentCodings(List<String> codings)

Configure the supported content codings in order of preference. The first coding that is present in the "Accept-Encoding" header for a given request, and that has a file present with the associated extension, is used.

Note: Each coding must be associated with a file extension via `registerExtension(java.lang.String, java.lang.String)` or `setExtensions(java.util.Map<java.lang.String, java.lang.String>)`. Also customizations to the list of codings here should be matched by customizations to the same list in `CachingResourceResolver` to ensure encoded variants of a resource are cached under separate keys.

By default this property is set to ["br", "gzip"].

Parameters:
  `codings` - one or more supported content codings

#### getContentCodings

    public List<String> getContentCodings()

Return a read-only list with the supported content codings.

#### setExtensions

    public void setExtensions(Map<String,String> extensions)

Configure mappings from content codings to file extensions. A dot "." will be prepended in front of the extension value if not present.

By default this is configured with ["br" -> ".br"] and ["gzip" -> ".gz"].

Parameters:
  `extensions` - the extensions to use.
See Also:
  `registerExtension(String, String)`

#### getExtensions

    public Map<String,String> getExtensions()

Return a read-only map with coding-to-extension mappings.

#### registerExtension

    public void registerExtension(String coding,
                                  String extension)

Java config friendly alternative to `setExtensions(Map)`.

Parameters:
  `coding` - the content coding
  `extension` - the associated file extension

#### resolveResourceInternal

    protected reactor.core.publisher.Mono<org.springframework.core.io.Resource> resolveResourceInternal(@Nullable
                                                                                                        org.springframework.web.server.ServerWebExchange exchange,
                                                                                                        String requestPath,
                                                                                                        List<? extends org.springframework.core.io.Resource> locations,
                                                                                                        ResourceResolverChain chain)

Specified by:
  `resolveResourceInternal` in class `AbstractResourceResolver`

#### resolveUrlPathInternal

    protected reactor.core.publisher.Mono<String> resolveUrlPathInternal(String resourceUrlPath,
                                                                         List<? extends org.springframework.core.io.Resource> locations,
                                                                         ResourceResolverChain chain)

Specified by:
  `resolveUrlPathInternal` in class `AbstractResourceResolver`