Fix isCommitted() check in response header filters#4115
Conversation
Add isCommitted() check to prevent UnsupportedOperationException when modifying response headers after request is rejected by filters like RequestRateLimiter. Affected filters: - SetResponseHeaderGatewayFilterFactory - DedupeResponseHeaderGatewayFilterFactory - SecureHeadersGatewayFilterFactory - RewriteResponseHeaderGatewayFilterFactory - RewriteLocationResponseHeaderGatewayFilterFactory Fixes spring-cloudgh-3718 Signed-off-by: chenwenshun <chenwenshun@gmail.com>
f0e9f45 to
41a238a
Compare
|
I am encountering the same problem in NettyRoutingFilter: It would be great if this could also be included in the fix. |
ryanjbaxter
left a comment
There was a problem hiding this comment.
Can you submit this against the 4.3.x branch?
| .then(Mono.fromRunnable(() -> dedupe(exchange.getResponse().getHeaders(), config))); | ||
| return chain.filter(exchange).then(Mono.fromRunnable(() -> { | ||
| if (!exchange.getResponse().isCommitted()) { | ||
| dedupe(exchange.getResponse().getHeaders(), config); |
There was a problem hiding this comment.
Similar to what AddResponseHeaderGatewayFilterFactory does it would be good to add the check to dedupe. Similar comment applies to the other filters
| * fix for issue #3718 where filters like RequestRateLimiter commit the response, but | ||
| * post-processing response header filters still try to modify headers. | ||
| * | ||
| * @author issue #3718 |
There was a problem hiding this comment.
Please fix the author tag
| * A filter that commits the response without calling chain.filter(), simulating | ||
| * behavior of filters like RequestRateLimiter when denying a request. | ||
| */ | ||
| static class CommitResponseFilter implements GatewayFilter { |
There was a problem hiding this comment.
This should probably implement Ordered to make runs before the other filters.
spencergibb
left a comment
There was a problem hiding this comment.
Without having investigated much, this looks like a bandaid to a bigger problem. I'd rather fix the root problem than cover it up. This looks to just do nothing, which seems worse to me.
What changes were proposed in this pull request?
Add
isCommitted()check to response header filters to preventUnsupportedOperationExceptionwhen response is already committedby filters like
RequestRateLimiter.Fix versions affected
What is the issue related to this PR?
Fixes #3718
How was this patch tested?
Existing tests pass. The issue occurs when:
With this fix, filters check
isCommitted()before modification.Checklist
./mvnw test)