using IOUtils.copy on the response outpoutstream inside a Spring controller reset any header modification
<p>I have a simple MVC controller with one endpoint that is meant to return a zip file.</p>

<pre><code> @RequestMapping(value = "/xxx", method = RequestMethod.GET, produces = "application/x-download")
  public String getZip(HttpServletResponse response)
     InputStream is = ...;
     IOUtils.copy(is, response.getOutputStream());
     response.setHeader(HttpHeaders.CONTENT_DISPOSITION, attachment; filename="myfile.zip");
     return ""; // If I dont return anything (void) headers don't get changed
}
</code></pre>

<p>When I hit this endpoint with chrome, the response header are missing Content-type and Content-Disposition all together! (normally for all requests I have at least Content-Type=application/json"</p>

<p>I have tried remvoving the IOUtils.copy</p>

<p>And now when I hit the endpoint the header are correct! I do have the right content-type and the content-disposition is there.</p>

<p>Could someone explain me why this is happening? is writing into the outputstream messing up the response?? 
Who do I return a zip in that case?</p>