title: C# HttpListener Response + GZipStream
body: <p>I use HttpListener for my own http server (I do not use IIS). I want to compress my OutputStream by GZip compression:</p>
  
  <pre><code>byte[] refBuffer = Encoding.UTF8.GetBytes(...some data source...);
  
  var varByteStream = new MemoryStream(refBuffer);
  
  System.IO.Compression.GZipStream refGZipStream = new GZipStream(varByteStream, CompressionMode.Compress, false);
  
  refGZipStream.BaseStream.CopyTo(refHttpListenerContext.Response.OutputStream);
  
  refHttpListenerContext.Response.AddHeader("Content-Encoding", "gzip");
  </code></pre>
  
  <p>But I getting error in Chrome:</p>
  
  <blockquote>
    <p>ERR_CONTENT_DECODING_FAILED</p>
  </blockquote>
  
  <p>If I remove AddHeader, then it works, but the size of response is not seems being compressed. What am I doing wrong?</p>