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.http.codec;
018
019import java.util.List;
020import java.util.Map;
021
022import org.springframework.core.ResolvableType;
023import org.springframework.core.codec.Encoder;
024import org.springframework.core.codec.Hints;
025import org.springframework.http.MediaType;
026import org.springframework.http.server.reactive.ServerHttpRequest;
027import org.springframework.http.server.reactive.ServerHttpResponse;
028import org.springframework.lang.Nullable;
029
030/**
031 * Extension of {@code Encoder} exposing extra methods relevant in the context
032 * of HTTP request or response body encoding.
033 *
034 * @author Rossen Stoyanchev
035 * @since 5.0
036 * @param <T> the type of elements in the input stream
037 */
038public interface HttpMessageEncoder<T> extends Encoder<T> {
039
040        /**
041         * Return "streaming" media types for which flushing should be performed
042         * automatically vs at the end of the input stream.
043         */
044        List<MediaType> getStreamingMediaTypes();
045
046        /**
047         * Get decoding hints based on the server request or annotations on the
048         * target controller method parameter.
049         * @param actualType the actual source type to encode, possibly a reactive
050         * wrapper and sourced from {@link org.springframework.core.MethodParameter},
051         * i.e. providing access to method annotations.
052         * @param elementType the element type within {@code Flux/Mono} that we're
053         * trying to encode.
054         * @param request the current request
055         * @param response the current response
056         * @return a Map with hints, possibly empty
057         */
058        default Map<String, Object> getEncodeHints(ResolvableType actualType, ResolvableType elementType,
059                        @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) {
060
061                return Hints.none();
062        }
063
064}