Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: GZipStream - incorrect Content-Length

$
0
0
Re: GZipStream - incorrect Content-Length
ASP.NET
Re: GZipStream - incorrect Content-Length
02/17/2012
12:46:44 PM
3FO1FFV5R Show this entire thread in new window
Gratar Image based on email address
From:
To:
Attachments:
None

Hmmm... I don't see that with my GZip content as described with these functions:

http://www.west-wind.com/weblog/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats

I think the issue you're having might be one of timing or caching. You need to make sure you only GZip after caching has occurred and if you do use Output caching you have to cache both GZipped and plain versions separately. Note that IIS will also cache itself with Kernal caching and that might also affect your request.

IOW, don't apply GZip in the BeginRequest module handler, but maybe in PreRequestHandlerExecute().

+++ Rick ---


Hello

I'm trying to compress the output of a WCF restful service, using GZipStream:

I put this in my global.asax:

protected void Application_BeginRequest(object sender, EventArgs e) { HttpResponse response = HttpContext.Current.Response; string AcceptEncoding = Request.Headers["Accept-Encoding"]; if (AcceptEncoding == null) return; if (AcceptEncoding.Contains("gzip")) { Logger.MainLogger.Info("gzip actif", AcceptEncoding, "GZipEncodePage"); response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AppendHeader("Content-Encoding", "gzip"); } else if (AcceptEncoding.Contains("deflate")) { Logger.MainLogger.Info("deflate actif", AcceptEncoding, "GZipEncodePage"); response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress); response.AppendHeader("Content-Encoding", "deflate"); response.AppendHeader("Vary", "Content-Encoding"); } }

The problem is that the field "Content-Length" of the response header still gets the value of the uncompressed stream.

For example, when I use fiddler to see what happens:
response header:
HTTP/1.1 200 OK
Date: Thu, 16 Feb 2012 14:25:32 GMT
Cache-Control: private
Content-Length: 472810
Content-Type: application/json
Content-Encoding: gzip
Vary: Content-Encoding

But I also get a fiddler pop up with the error:
Fiddler has detected a protocol violation in session #569.
Content-Length mismatch: Response Header indicated 472 810 bytes, but server sent 152 488 bytes.


Do you know what I've done wrong ?
Thanks


Rick Strahl
West Wind Technologies

Making waves on the Web

from Maui, Hawaii
West Wind Web Monitor

Viewing all articles
Browse latest Browse all 10393

Trending Articles