-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
Martin Frey opened SPR-13867 and commented
Hi
I think there might a bug with some new implementation inside RequestMappingHandlerAdapter resulting in no-cache, no-store headers even when using an explicit ResponseEntity.
Controller
@RequestMapping(value = "/somejson", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<TopLevel> getCurrent() {
TopLevel t = new TopLevel();
return ResponseEntity.ok().cacheControl(CacheControl.maxAge(6000, TimeUnit.SECONDS)).body(body);
}
Resulting in this header
Cache-Control=no-cache, no-store, max-age=0, must-revalidate, max-age=6000
I would expect that this code inside the RequestMappingHandlerAdapter should not be called in such a case when a ResponseEntity is the outcome of a RequestMapping
@Override
protected ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
checkRequest(request);
if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
applyCacheSeconds(response, this.cacheSecondsForSessionAttributeHandlers);
}
else {
prepareResponse(response);
}
.
.
.
}
FROM WebContentGenerator
/**
* Prepare the given response according to the settings of this generator.
* Applies the number of cache seconds specified for this generator.
* @param response current HTTP response
* @since 4.2
*/
protected final void prepareResponse(HttpServletResponse response) {
if (this.cacheControl != null) {
applyCacheControl(response, this.cacheControl);
}
else {
applyCacheSeconds(response, this.cacheSeconds);
}
}
Affects: 4.2.3
Issue Links:
- Regression: RequestMappingHandlerAdapter with synchronizeOnSession=true calls invokeHandlerMethod twice [SPR-13999] #18572 Regression: RequestMappingHandlerAdapter with synchronizeOnSession=true calls invokeHandlerMethod twice
- Regression: ResourceHandlerRegistration setCachePeriod doesn't set the correct response header anymore [SPR-14005] #18577 Regression: ResourceHandlerRegistration setCachePeriod doesn't set the correct response header anymore
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug