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.server.handler;
018
019import java.util.List;
020
021import reactor.core.publisher.Mono;
022
023import org.springframework.web.server.ServerWebExchange;
024import org.springframework.web.server.WebFilter;
025import org.springframework.web.server.WebHandler;
026
027/**
028 * {@link WebHandlerDecorator} that invokes a chain of {@link WebFilter WebFilters}
029 * before invoking the delegate {@link WebHandler}.
030 *
031 * @author Rossen Stoyanchev
032 * @since 5.0
033 */
034public class FilteringWebHandler extends WebHandlerDecorator {
035
036        private final DefaultWebFilterChain chain;
037
038
039        /**
040         * Constructor.
041         * @param filters the chain of filters
042         */
043        public FilteringWebHandler(WebHandler handler, List<WebFilter> filters) {
044                super(handler);
045                this.chain = new DefaultWebFilterChain(handler, filters);
046        }
047
048
049        /**
050         * Return a read-only list of the configured filters.
051         */
052        public List<WebFilter> getFilters() {
053                return this.chain.getFilters();
054        }
055
056
057        @Override
058        public Mono<Void> handle(ServerWebExchange exchange) {
059                return this.chain.filter(exchange);
060        }
061
062}