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.accept;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.springframework.http.MediaType;
023import org.springframework.web.server.NotAcceptableStatusException;
024import org.springframework.web.server.ServerWebExchange;
025
026/**
027 * Strategy to resolve the requested media types for a {@code ServerWebExchange}.
028 *
029 * <p>See {@link RequestedContentTypeResolverBuilder} to create a sequence of
030 * strategies.
031 *
032 * @author Rossen Stoyanchev
033 * @since 5.0
034 */
035public interface RequestedContentTypeResolver {
036
037        /**
038         * A singleton list with {@link MediaType#ALL} that is returned from
039         * {@link #resolveMediaTypes} when no specific media types are requested.
040         * @since 5.0.5
041         */
042        List<MediaType> MEDIA_TYPE_ALL_LIST = Collections.singletonList(MediaType.ALL);
043
044
045        /**
046         * Resolve the given request to a list of requested media types. The returned
047         * list is ordered by specificity first and by quality parameter second.
048         * @param exchange the current exchange
049         * @return the requested media types, or {@link #MEDIA_TYPE_ALL_LIST} if none
050         * were requested.
051         * @throws NotAcceptableStatusException if the requested media type is invalid
052         */
053        List<MediaType> resolveMediaTypes(ServerWebExchange exchange);
054
055}