Add status_code to the OutputTransform.transform_first_chunk interface.
This is needed for correct support of the 304 status code, which has no body and should not have either a Content-Length or Transfer-Encoding. This is a backwards-incompatible change to an interface that was never technically private, but not included in the documentation and as far as I can tell was never used outside tornado itself.
This commit is contained in:
parent
53452e8d5a
commit
dd7655964a
|
@ -633,8 +633,9 @@ class RequestHandler(object):
|
||||||
if not self._headers_written:
|
if not self._headers_written:
|
||||||
self._headers_written = True
|
self._headers_written = True
|
||||||
for transform in self._transforms:
|
for transform in self._transforms:
|
||||||
self._headers, chunk = transform.transform_first_chunk(
|
self._status_code, self._headers, chunk = \
|
||||||
self._headers, chunk, include_footers)
|
transform.transform_first_chunk(
|
||||||
|
self._status_code, self._headers, chunk, include_footers)
|
||||||
headers = self._generate_headers()
|
headers = self._generate_headers()
|
||||||
else:
|
else:
|
||||||
for transform in self._transforms:
|
for transform in self._transforms:
|
||||||
|
@ -1668,8 +1669,8 @@ class OutputTransform(object):
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def transform_first_chunk(self, headers, chunk, finishing):
|
def transform_first_chunk(self, status_code, headers, chunk, finishing):
|
||||||
return headers, chunk
|
return status_code, headers, chunk
|
||||||
|
|
||||||
def transform_chunk(self, chunk, finishing):
|
def transform_chunk(self, chunk, finishing):
|
||||||
return chunk
|
return chunk
|
||||||
|
@ -1690,7 +1691,7 @@ class GZipContentEncoding(OutputTransform):
|
||||||
self._gzipping = request.supports_http_1_1() and \
|
self._gzipping = request.supports_http_1_1() and \
|
||||||
"gzip" in request.headers.get("Accept-Encoding", "")
|
"gzip" in request.headers.get("Accept-Encoding", "")
|
||||||
|
|
||||||
def transform_first_chunk(self, headers, chunk, finishing):
|
def transform_first_chunk(self, status_code, headers, chunk, finishing):
|
||||||
if self._gzipping:
|
if self._gzipping:
|
||||||
ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
|
ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
|
||||||
self._gzipping = (ctype in self.CONTENT_TYPES) and \
|
self._gzipping = (ctype in self.CONTENT_TYPES) and \
|
||||||
|
@ -1704,7 +1705,7 @@ class GZipContentEncoding(OutputTransform):
|
||||||
chunk = self.transform_chunk(chunk, finishing)
|
chunk = self.transform_chunk(chunk, finishing)
|
||||||
if "Content-Length" in headers:
|
if "Content-Length" in headers:
|
||||||
headers["Content-Length"] = str(len(chunk))
|
headers["Content-Length"] = str(len(chunk))
|
||||||
return headers, chunk
|
return status_code, headers, chunk
|
||||||
|
|
||||||
def transform_chunk(self, chunk, finishing):
|
def transform_chunk(self, chunk, finishing):
|
||||||
if self._gzipping:
|
if self._gzipping:
|
||||||
|
@ -1727,7 +1728,7 @@ class ChunkedTransferEncoding(OutputTransform):
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
self._chunking = request.supports_http_1_1()
|
self._chunking = request.supports_http_1_1()
|
||||||
|
|
||||||
def transform_first_chunk(self, headers, chunk, finishing):
|
def transform_first_chunk(self, status_code, headers, chunk, finishing):
|
||||||
if self._chunking:
|
if self._chunking:
|
||||||
# No need to chunk the output if a Content-Length is specified
|
# No need to chunk the output if a Content-Length is specified
|
||||||
if "Content-Length" in headers or "Transfer-Encoding" in headers:
|
if "Content-Length" in headers or "Transfer-Encoding" in headers:
|
||||||
|
@ -1735,7 +1736,7 @@ class ChunkedTransferEncoding(OutputTransform):
|
||||||
else:
|
else:
|
||||||
headers["Transfer-Encoding"] = "chunked"
|
headers["Transfer-Encoding"] = "chunked"
|
||||||
chunk = self.transform_chunk(chunk, finishing)
|
chunk = self.transform_chunk(chunk, finishing)
|
||||||
return headers, chunk
|
return status_code, headers, chunk
|
||||||
|
|
||||||
def transform_chunk(self, block, finishing):
|
def transform_chunk(self, block, finishing):
|
||||||
if self._chunking:
|
if self._chunking:
|
||||||
|
|
Loading…
Reference in New Issue