MCPcopy
hub / github.com/tornadoweb/tornado / transform_first_chunk

Method transform_first_chunk

tornado/web.py:3327–3362  ·  view source on GitHub ↗
(
        self,
        status_code: int,
        headers: httputil.HTTPHeaders,
        chunk: bytes,
        finishing: bool,
    )

Source from the content-addressed store, hash-verified

3325 return ctype.startswith("text/") or ctype in self.CONTENT_TYPES
3326
3327 def transform_first_chunk(
3328 self,
3329 status_code: int,
3330 headers: httputil.HTTPHeaders,
3331 chunk: bytes,
3332 finishing: bool,
3333 ) -> Tuple[int, httputil.HTTPHeaders, bytes]:
3334 # TODO: can/should this type be inherited from the superclass?
3335 if "Vary" in headers:
3336 headers["Vary"] += ", Accept-Encoding"
3337 else:
3338 headers["Vary"] = "Accept-Encoding"
3339 if self._gzipping:
3340 ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
3341 self._gzipping = (
3342 self._compressible_type(ctype)
3343 and (not finishing or len(chunk) >= self.MIN_LENGTH)
3344 and ("Content-Encoding" not in headers)
3345 )
3346 if self._gzipping:
3347 headers["Content-Encoding"] = "gzip"
3348 self._gzip_value = BytesIO()
3349 self._gzip_file = gzip.GzipFile(
3350 mode="w", fileobj=self._gzip_value, compresslevel=self.GZIP_LEVEL
3351 )
3352 chunk = self.transform_chunk(chunk, finishing)
3353 if "Content-Length" in headers:
3354 # The original content length is no longer correct.
3355 # If this is the last (and only) chunk, we can set the new
3356 # content-length; otherwise we remove it and fall back to
3357 # chunked encoding.
3358 if finishing:
3359 headers["Content-Length"] = str(len(chunk))
3360 else:
3361 del headers["Content-Length"]
3362 return status_code, headers, chunk
3363
3364 def transform_chunk(self, chunk: bytes, finishing: bool) -> bytes:
3365 if self._gzipping:

Callers

nothing calls this directly

Calls 4

_compressible_typeMethod · 0.95
transform_chunkMethod · 0.95
splitMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected