Clear ProducesRequestCondition attribute

Closes gh-23091
This commit is contained in:
Rossen Stoyanchev
2019-06-11 13:55:20 -04:00
parent 859923b732
commit 0757eaee9d
4 changed files with 43 additions and 0 deletions

View File

@@ -320,6 +320,17 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
}
/**
* Use this to clear {@link #MEDIA_TYPES_ATTRIBUTE} that contains the parsed,
* requested media types.
* @param exchange the current exchange
* @since 5.2
*/
public static void clearMediaTypesAttribute(ServerWebExchange exchange) {
exchange.getAttributes().remove(MEDIA_TYPES_ATTRIBUTE);
}
/**
* Parses and matches a single media type expression to a request's 'Accept' header.
*/

View File

@@ -24,6 +24,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Predicate;
import reactor.core.publisher.Mono;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.MergedAnnotation;
@@ -43,9 +45,11 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
import org.springframework.web.reactive.result.condition.ConsumesRequestCondition;
import org.springframework.web.reactive.result.condition.ProducesRequestCondition;
import org.springframework.web.reactive.result.condition.RequestCondition;
import org.springframework.web.reactive.result.method.RequestMappingInfo;
import org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
/**
* An extension of {@link RequestMappingInfoHandlerMapping} that creates
@@ -352,4 +356,10 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
}
}
@Override
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
return super.getHandlerInternal(exchange)
.doOnTerminate(() -> ProducesRequestCondition.clearMediaTypesAttribute(exchange));
}
}