So I am compressing my output stream via an action filter:
var response = filterContext.HttpContext.Response;
response.Filter = new DeflateStream(response.Filter
I'm not seeing much wrong with the code above however you may want to try this approach:
var response = filterContext.HttpContext.Response;
using(var wsf = new WhitespaceFilter(response.Filter))
{
wsf.Flush();
response.Filter = new DefalteStream(wsf, CompressMode.Compress);
}
BTW are you using this attribute approach when applying the compressing and white space removal:
http://www.avantprime.com/articles/view-article/7/compress-httpresponse-for-your-controller-actions-using-attributes
DaTribe
For those who get this far... you can do it... just swap the order of the stream chaining:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var response = filterContext.HttpContext.Response;
// - COMPRESS
HttpRequestBase request = filterContext.HttpContext.Request;
string acceptEncoding = request.Headers["Accept-Encoding"];
if (!String.IsNullOrEmpty(acceptEncoding))
{
acceptEncoding = acceptEncoding.ToUpperInvariant();
if (acceptEncoding.Contains("GZIP"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (acceptEncoding.Contains("DEFLATE"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
// - REMOVE WHITE SPACE
response.Filter = new WhitespaceFilter(response.Filter);
}