title: Using Response.Filter with Response.TransmitFile
body: <p>I'm using Response.Filter in order to implement stream compression in accordance with HTTP Request Header <code>Accept-Encoding</code></p>
  
  <p>Here's the important stuff:</p>
  
  <pre><code>        if (AcceptEncoding.Contains("deflate") || AcceptEncoding == "*")
          {
               HttpApp.Response.Filter = new DeflateStream(PreviousOutputStream, CompressionMode.Compress);
               HttpApp.Response.AppendHeader("Content-Encoding", "deflate");
          }
  </code></pre>
  
  <p>By and large this works as intended. However, I'm in a situation where I'm using an <code>ActionResult</code> on an MVC Controller to serve up files to the user agent:</p>
  
  <pre><code>        Response.Clear();
          Response.Headers["Content-Type"] = contentType;
          Response.Headers["Content-Length"] = contentLength;
  
          if (Request.QueryString["dl"] == "1")
          {
              Response.Headers["Content-Disposition"] = "attachment; filename=" + fileInfo.Name;
          }
  
          Response.Flush();
          Response.TransmitFile(fileInfo.FullName);
  </code></pre>
  
  <p>To be more exact, the action method returns <code>new EmptyResult()</code> after the <code>Response.TransmitFile()</code> call. This works exactly as intended without the Response.Filter modification.</p>
  
  <p>In this situation, the response entity reaches the user agent garbled and unintelligible. FireFox's Poster addon shows empty entities or jumbled entities coming back.</p>