diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/CustomHeaderHttpFilter.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/CustomHeaderHttpFilter.java index 828eb946..35f54596 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/CustomHeaderHttpFilter.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/filter/CustomHeaderHttpFilter.java @@ -20,13 +20,14 @@ public void doProcessRequest(ServletRequest servletRequest, RequestParams 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 diff --git a/guice/src/main/java/com/flipkart/gjex/http/interceptor/HttpFilterInterceptor.java b/guice/src/main/java/com/flipkart/gjex/http/interceptor/HttpFilterInterceptor.java index 64aa7843..ff3bc6d0 100644 --- a/guice/src/main/java/com/flipkart/gjex/http/interceptor/HttpFilterInterceptor.java +++ b/guice/src/main/java/com/flipkart/gjex/http/interceptor/HttpFilterInterceptor.java @@ -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 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()); }