Skip to content

Commit 2e49441

Browse files
committed
Fix condition in ServletInvocableHandlerMethod
Closes gh-23775
1 parent 38a1cae commit 2e49441

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private boolean isRequestNotModified(ServletWebRequest webRequest) {
165165
}
166166

167167
private void disableContentCachingIfNecessary(ServletWebRequest webRequest) {
168-
if (!isRequestNotModified(webRequest)) {
168+
if (isRequestNotModified(webRequest)) {
169169
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
170170
Assert.notNull(response, "Expected HttpServletResponse");
171171
if (StringUtils.hasText(response.getHeader("ETag"))) {

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import org.springframework.core.MethodParameter;
3232
import org.springframework.core.ResolvableType;
3333
import org.springframework.core.annotation.AliasFor;
34+
import org.springframework.http.HttpHeaders;
3435
import org.springframework.http.HttpStatus;
3536
import org.springframework.http.ResponseEntity;
3637
import org.springframework.http.converter.HttpMessageConverter;
@@ -46,6 +47,7 @@
4647
import org.springframework.web.context.request.NativeWebRequest;
4748
import org.springframework.web.context.request.ServletWebRequest;
4849
import org.springframework.web.context.request.async.DeferredResult;
50+
import org.springframework.web.filter.ShallowEtagHeaderFilter;
4951
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
5052
import org.springframework.web.method.support.HandlerMethodArgumentResolverComposite;
5153
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
@@ -139,6 +141,21 @@ public void invokeAndHandle_VoidRequestNotModified() throws Exception {
139141
this.mavContainer.isRequestHandled());
140142
}
141143

144+
@Test // gh-23775
145+
public void invokeAndHandle_VoidNotModifiedWithEtag() throws Exception {
146+
String etag = "\"deadb33f8badf00d\"";
147+
this.request.addHeader(HttpHeaders.IF_NONE_MATCH, etag);
148+
this.webRequest.checkNotModified(etag);
149+
150+
ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "notModified");
151+
handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);
152+
153+
assertTrue("Null return value + 'not modified' request should result in 'request handled'",
154+
this.mavContainer.isRequestHandled());
155+
156+
assertEquals(true, this.request.getAttribute(ShallowEtagHeaderFilter.class.getName() + ".STREAMING"));
157+
}
158+
142159
@Test // SPR-9159
143160
public void invokeAndHandle_NotVoidWithResponseStatusAndReason() throws Exception {
144161
ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "responseStatusWithReason");

0 commit comments

Comments
 (0)