Skip to content

Commit 37dbef4

Browse files
committed
Clear fewer headers on 1xx/204/304 responses
This function is called on more than just 304 responses; it’s important to permit the Allow header on 204 responses. Also, the relevant RFCs have changed significantly. Fixes tornadoweb#2726. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 8e5ecad commit 37dbef4

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

tornado/web.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def finish(self, chunk: Optional[Union[str, bytes, dict]] = None) -> "Future[Non
11381138
assert not self._write_buffer, (
11391139
"Cannot send body with %s" % self._status_code
11401140
)
1141-
self._clear_headers_for_304()
1141+
self._clear_representation_headers()
11421142
elif "Content-Length" not in self._headers:
11431143
content_length = sum(len(part) for part in self._write_buffer)
11441144
self.set_header("Content-Length", content_length)
@@ -1803,20 +1803,15 @@ def render(*args, **kwargs) -> str: # type: ignore
18031803
def _ui_method(self, method: Callable[..., str]) -> Callable[..., str]:
18041804
return lambda *args, **kwargs: method(self, *args, **kwargs)
18051805

1806-
def _clear_headers_for_304(self) -> None:
1807-
# 304 responses should not contain entity headers (defined in
1808-
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1)
1806+
def _clear_representation_headers(self) -> None:
1807+
# 304 responses should not representation metadata headers (defined in
1808+
# https://tools.ietf.org/html/rfc7231#section-3.1)
18091809
# not explicitly allowed by
1810-
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
1810+
# https://tools.ietf.org/html/rfc7232#section-4.1
18111811
headers = [
1812-
"Allow",
18131812
"Content-Encoding",
18141813
"Content-Language",
1815-
"Content-Length",
1816-
"Content-MD5",
1817-
"Content-Range",
18181814
"Content-Type",
1819-
"Last-Modified",
18201815
]
18211816
for h in headers:
18221817
self.clear_header(h)

0 commit comments

Comments
 (0)