Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove statusCode state from ContentCachingResponseWrapper #23490

Closed
lpickford-yozu opened this issue Aug 20, 2019 · 1 comment
Closed

Remove statusCode state from ContentCachingResponseWrapper #23490

lpickford-yozu opened this issue Aug 20, 2019 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@lpickford-yozu
Copy link

As part of one of our services we have a HandlerInterceptor which has some logic dependant on the status code of the response. As such we've been using a ContentCachingResponseWrapper in order to gain access to the body of the response object dependant on if the response object's status is equal to certain values.

When our ControllerAdvice catches an exception the status of the resultant response is set, and the response is then intercepted by our HandlerInterceptor implementation.

Inside the HandlerInterceptor we wrap the response object with ContentCachingResponseWrapper, and at this point the status and statusCode do not match. I believe this is because the ctor for ContollerAdvice ultimately does not set statusCode, but defaults to HttpServletResponse.SC_OK instead, where I believe it should default to the status of the response being passed in.

Is there a reason why statusCode is separate to status? Or would it make sense moving forwards to use setStatus and getStatus and have getStatusCode just forward to getStatus to preserve backwards compatibility?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 20, 2019
@rstoyanchev rstoyanchev self-assigned this Aug 21, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 21, 2019
@rstoyanchev rstoyanchev added this to the 5.2 RC2 milestone Aug 21, 2019
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Aug 21, 2019

It looks like getStatus() was only added in Servlet 3.1 which in Spring Framework 5 is a minimum requirement, so we can remove the statusCode field and deprecate the getStatusCode() method.

@rstoyanchev rstoyanchev changed the title statusCode is not synonymous with status at all times in ContentCachingResponseWrapper Remove statusCode from ContentCachingResponseWrapper Aug 21, 2019
@rstoyanchev rstoyanchev changed the title Remove statusCode from ContentCachingResponseWrapper Remove statusCode state from ContentCachingResponseWrapper Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants