Beispiel #1
0
 public override Tuple<int, HTTPHeaders, byte[]> transform_first_chunk(int status_code, HTTPHeaders headers, byte[] chunk, bool finishing)
 {
     // 304 responses have no body (not even a zero-length body), and so
     // should not have either Content-Length or Transfer-Encoding headers.
     if (_chunking && status_code != 304)
     {
         // No need to chunk the output if a Content-Length is specified
         if (headers.ContainsKey("Content-Length") || headers.ContainsKey("Transfer-Encoding"))
             _chunking = false;
         else
         {
             headers["Transfer-Encoding"] = "chunked";
             chunk = transform_chunk(chunk, finishing);
         }
     }
     return new Tuple<int, HTTPHeaders, byte[]>(status_code, headers, chunk);
 }
Beispiel #2
0
 public override Tuple<int, HTTPHeaders, byte[]> transform_first_chunk(int status_code, HTTPHeaders headers, byte[] chunk, bool finishing)
 {
     if (_gzipping)
     {
         var ctype = headers.get("Content-Type", "").Split(';')[0];
         _gzipping = CONTENT_TYPES.Contains(ctype) &&
             (!finishing || chunk.Length >= MIN_LENGTH) &&
             (finishing || !headers.ContainsKey("Content-Length")) &&
             (!headers.ContainsKey("Content-Encoding"));
     }
     if (_gzipping)
     {
         headers["Content-Encoding"] = "gzip";
         _gzip_value = new MemoryStream(); // BytesIO();
         //_gzip_file = gzip.GzipFile(mode = "w", fileobj = self._gzip_value);
         _gzip_file = new GZipStream(_gzip_value, CompressionMode.Compress);
         chunk = transform_chunk(chunk, finishing);
         if (headers.ContainsKey("Content-Length"))
             headers["Content-Length"] = chunk.Length.ToString();
     }
     return new Tuple<int, HTTPHeaders, byte[]>(status_code, headers, chunk);
 }