Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZIP output stream

I am trying to GZIP some XML that gets streamed over HTTP (not a web service)

if (ZipOutput)
{
    output = new GZipStream(Context.Response.OutputStream, CompressionMode.Compress);
    Context.Response.AppendHeader("Content-Encoding", "gzip");
}
else
{
    output = Context.Response.OutputStream;
}

EscapeXMLTextWriter xmlWriter = new EscapeXMLTextWriter(output, new UTF8Encoding())
{
    Formatting = Formatting.Indented
};

ZipOutput is true, but the response doesn't seem to be zipped. Any pointers, alternative techniques?

I know I could use SharpZipLib, but wanted to use the GZipStream class in the framework.

like image 533
Matt Evans Avatar asked Apr 23 '26 13:04

Matt Evans


2 Answers

It looks to me like your code should work - maybe step through it with a debugger to check that the code is really being called as you think it is.

There's a good article on this (including one alternative technique) at - http://www.west-wind.com/weblog/posts/2007/Feb/05/More-on-GZip-compression-with-ASPNET-Content

like image 84
Stuart Avatar answered Apr 26 '26 01:04

Stuart


I figured this issue out I think - it turned out the office firewall was stripping the Accept-Encoding header on outbound requests.

like image 41
Matt Evans Avatar answered Apr 26 '26 02:04

Matt Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!