Skip to content

Commit

Permalink
Allow modifications from http-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Aug 9, 2024
1 parent 22e48de commit fc7843b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public void doProcessRequest(ServletRequest servletRequest, RequestParams<Map<St
@Override
public void doProcessResponseHeaders(Map<String, String> responseHeaders) {
super.doProcessResponseHeaders(responseHeaders);
responseHeaders.put("x-custom-doProcessResponseHeaders", "custom-header-value");
}

@Override
public void doProcessResponse(ServletResponse response) {
super.doProcessResponse(response);
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.addHeader("x-custom-header", "custom-header-value");
httpServletResponse.addHeader("x-custom-doProcessResponse", "custom-header-value");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ public final void doFilter(ServletRequest request, ServletResponse response,
try {
filters.forEach(filter -> filter.doProcessRequest(request, requestParams));
chain.doFilter(request, responseWrapper);

// Allow the filters to process the response headers
Map<String, String> responseHeaders = responseWrapper.getHeaderNames()
.stream().collect(Collectors.toMap(h -> h, httpServletResponse::getHeader));
filters.forEach(filter -> filter.doProcessResponseHeaders(responseHeaders));

responseHeaders.forEach(responseWrapper::setHeader);
} finally {
// Allow the filters to process the response
filters.forEach(filter -> filter.doProcessResponse(responseWrapper));
response.getOutputStream().write(responseWrapper.getWrapperBytes());
}
Expand Down

0 comments on commit fc7843b

Please sign in to comment.