Skip to content

AbstractRequestLoggingFilter with startAsync: unwrap request to find ContentCachingRequestWrapper [SPR-13764] #18338

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

Closed
spring-projects-issues opened this issue Dec 5, 2015 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Andreas Voellmy opened SPR-13764 and commented

In a subclass of AbstractRequestLoggingFilter in beforeRequest(), the request parameter is an instance of ContentCachingRequestWrapper, which allows createMessage(), or subclass code to access the cached content. However, in an asynchronous method return, the request passed to afterRequest() is not an instance of ContentCachingRequestWrapper, so createMessage() doesn't include cached contents. The request object does wrap a ContentCachingRequestWrapper, but the immediate request object is not an instance of ContentCachingRequestWrapper. It seems like it would better if the request argument to afterRequest was also an instance of ContentCachingRequestWrapper.


Affects: 4.1 GA, 4.2 GA

Backported to: 4.1.9

@spring-projects-issues
Copy link
Collaborator Author

Andreas Voellmy commented

It seems that, at least in my test case, there are some other filters, like org.springframework.security.web.FilterChainProxy that are included on the chain in the ASYNC dispatch, and these wrap the request. By the time the AbstractRequestLoggingFilter instance is reached, the ContentCachingRequestWrapper is wrapped twice.

Seems like there are two possibilities: (1) always ensure AbstractRequestLoggingFilter is last in the filter chain, (2) have a more robust way of getting the cached content. A "hack" for implementing (2) would be to unwrap wrapped requests until a ContentCachingRequestWrapper is found.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Actually, unwrapping the request is not a hack: It's the common technique applied for such Servlet Filter scenarios. We do it in a couple of other places already, so I'll revise AbstractRequestLoggingFilter along those lines for 4.2.4 and 4.1.9.

Juergen

@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.4 milestone Jan 11, 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) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants