I am trying to create a Java \"Filter\" which detects a custom HTTP Request Header, and inserts response headers so that the file will download automatically. The response
Assuming you use a response wrapper as described here by others, the whole secret is when to call getWriter() on the original response! That's because the response object ignores all headers added AFTER you asked for a writer!
So, make sure you add all your headers Before you call getWriter(). Here is my recommended sequence for doFilter():
Create a response wrapper
chain.doFilter (origRequest, wrapper);
Assign all required headers to the original (!) Response
Get writer from original response
Copy the wrapper's content to this writer