MCPcopy Create free account
hub / github.com/EasyIME/PIME / transform_first_chunk

Method transform_first_chunk

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

Source from the content-addressed store, hash-verified

3124 return ctype.startswith("text/") or ctype in self.CONTENT_TYPES
3125
3126 def transform_first_chunk(
3127 self,
3128 status_code: int,
3129 headers: httputil.HTTPHeaders,
3130 chunk: bytes,
3131 finishing: bool,
3132 ) -> Tuple[int, httputil.HTTPHeaders, bytes]:
3133 # TODO: can/should this type be inherited from the superclass?
3134 if "Vary" in headers:
3135 headers["Vary"] += ", Accept-Encoding"
3136 else:
3137 headers["Vary"] = "Accept-Encoding"
3138 if self._gzipping:
3139 ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
3140 self._gzipping = (
3141 self._compressible_type(ctype)
3142 and (not finishing or len(chunk) >= self.MIN_LENGTH)
3143 and ("Content-Encoding" not in headers)
3144 )
3145 if self._gzipping:
3146 headers["Content-Encoding"] = "gzip"
3147 self._gzip_value = BytesIO()
3148 self._gzip_file = gzip.GzipFile(
3149 mode="w", fileobj=self._gzip_value, compresslevel=self.GZIP_LEVEL
3150 )
3151 chunk = self.transform_chunk(chunk, finishing)
3152 if "Content-Length" in headers:
3153 # The original content length is no longer correct.
3154 # If this is the last (and only) chunk, we can set the new
3155 # content-length; otherwise we remove it and fall back to
3156 # chunked encoding.
3157 if finishing:
3158 headers["Content-Length"] = str(len(chunk))
3159 else:
3160 del headers["Content-Length"]
3161 return status_code, headers, chunk
3162
3163 def transform_chunk(self, chunk: bytes, finishing: bool) -> bytes:
3164 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