Clear ProducesRequestCondition attribute
Closes gh-23091
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -326,6 +326,17 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this to clear {@link #MEDIA_TYPES_ATTRIBUTE} that contains the parsed,
|
||||
* requested media types.
|
||||
* @param request the current request
|
||||
* @since 5.2
|
||||
*/
|
||||
public static void clearMediaTypesAttribute(HttpServletRequest request) {
|
||||
request.removeAttribute(MEDIA_TYPES_ATTRIBUTE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses and matches a single media type expression to a request's 'Accept' header.
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.web.servlet.handler.RequestMatchResult;
|
||||
import org.springframework.web.servlet.mvc.condition.AbstractRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.CompositeRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestCondition;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
@@ -441,4 +442,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
|
||||
try {
|
||||
return super.getHandlerInternal(request);
|
||||
}
|
||||
finally {
|
||||
ProducesRequestCondition.clearMediaTypesAttribute(request);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user