001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.reactive.resource;
018
019import java.util.List;
020
021import reactor.core.publisher.Mono;
022
023import org.springframework.core.io.Resource;
024import org.springframework.lang.Nullable;
025import org.springframework.web.server.ServerWebExchange;
026
027/**
028 * A contract for invoking a chain of {@link ResourceResolver ResourceResolvers} where each resolver
029 * is given a reference to the chain allowing it to delegate when necessary.
030 *
031 * @author Rossen Stoyanchev
032 * @since 5.0
033 */
034public interface ResourceResolverChain {
035
036        /**
037         * Resolve the supplied request and request path to a {@link Resource} that
038         * exists under one of the given resource locations.
039         * @param exchange the current exchange
040         * @param requestPath the portion of the request path to use
041         * @param locations the locations to search in when looking up resources
042         * @return the resolved resource; or an empty {@code Mono} if unresolved
043         */
044        Mono<Resource> resolveResource(@Nullable ServerWebExchange exchange, String requestPath,
045                        List<? extends Resource> locations);
046
047        /**
048         * Resolve the externally facing <em>public</em> URL path for clients to use
049         * to access the resource that is located at the given <em>internal</em>
050         * resource path.
051         * <p>This is useful when rendering URL links to clients.
052         * @param resourcePath the internal resource path
053         * @param locations the locations to search in when looking up resources
054         * @return the resolved public URL path; or an empty {@code Mono} if unresolved
055         */
056        Mono<String> resolveUrlPath(String resourcePath, List<? extends Resource> locations);
057
058}