Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP Response GZip Compression
    primarykey
    data
    text
    <p>I have a Proxy which handles HTTP Requests. </p> <p>Now when I get a GZipped HTTP Response, I'm decompressing it like :</p> <pre><code>MemoryStream ms = new MemoryStream(); if (response.ContentLength &gt; 0) buffer = new Byte[response.ContentLength]; else buffer = new Byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) &gt; 0) { ms.Write(buffer, 0, bytesRead); } string resp = ""; if (response.ContentEncoding == "gzip") resp = Utilities.GZip.Unzip(ms.ToArray()); else resp = Encoding.UTF8.GetString(ms.ToArray()); </code></pre> <p>Where Utilities.GZip.Unzip does:</p> <pre><code>using (var msi = new MemoryStream(bytes)) using (var mso = new MemoryStream()) { using (var gs = new GZipStream(msi, CompressionMode.Decompress)) { CopyTo(gs, mso); } return Encoding.UTF8.GetString(mso.ToArray()); } </code></pre> <p>So far everything's fine, I can read the HTML.</p> <p>Now I have to Write the Response back to the Client who requested it.</p> <p>Like this:</p> <pre><code>byte[] outByte; if (response.ContentEncoding == "gzip") outByte = Utilities.GZip.Zip(resp); else outByte = Encoding.UTF8.GetBytes(resp); outStream.Write(outByte, 0, outByte.Length); </code></pre> <p>Where Utilities.GZip.Zip does:</p> <pre><code>var bytes = Encoding.UTF8.GetBytes(str); using (var msi = new MemoryStream(bytes)) using (var mso = new MemoryStream()) { using (var gs = new GZipStream(mso, CompressionMode.Compress)) { CopyTo(msi, gs); } return mso.ToArray(); } </code></pre> <p>Now it's a really strange behaviour, the response byte-Array has a Length of 16990 (zipped), but my own zipped byte-Array has a Length of 19379.</p> <p>The client get's a response, but it's cutted off.</p> <p>Any suggestions?</p> <p><strong>EDIT:</strong></p> <p>For your information, as I send the original MemoryStream unchanged to the Client everythings fine!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload