Repository navigation
Conversation
ceb6aea to
03761c5
Compare
|
Rebased onto master ( |
|
HEAD and 304 are special-cased because of their relationship with GET and 200: it makes sense to implement them by generating a regular response and throwing it away. (the special case for 304 was incomplete, so it's good to throw away the body here). But for 1xx and 204, I think it's appropriate that an error is raised if the wsgi application tries to send a body; we shouldn't silently throw it away. |
Review feedback: HEAD and 304 discard a body because they describe a GET or a cached 200. A body for 1xx or 204 is an application error, so it should not be silently dropped. Keep discarding for HEAD and 304, and raise ValueError for a non-empty body on 1xx/204; the container logs it and sends the fallback 500. The 204 header-stripping test now uses an empty body. New tests cover a 204 body and a 103 body through a raw container, because the WSGI validator rejects those apps before the container sees them.
|
Agreed — changed in |
The validator only rejects the 103 app, and only because a non-204/304 response needs a Content-Type; it accepts a 204 with a body. Keep the 103 case on the raw container and move the 204 body case back through the validator wrapper, so the comment and the test setup agree.
| if status_code != 304: | ||
| # HEAD and 304 discard a body because they describe a GET or a | ||
| # cached 200. A body for 1xx or 204 is an application error, so it | ||
| # is not silently dropped. |
There was a problem hiding this comment.
Similarly, a non-zero content-length should also be an error instead of being silently dropped. I think a non-empty transfer-encoding should also be an error (it's never legal to send transfer-encoding: chunked with an empty body so it would never make sense here), but I'm less sure of that.
There was a problem hiding this comment.
Done in 8bce2372: a non-zero Content-Length or a non-empty Transfer-Encoding on 1xx/204 now raises ValueError (fallback 500); Content-Length: 0 is still dropped, and HEAD/304 semantics are unchanged. New tests cover a 204 with a non-zero Content-Length and one with Transfer-Encoding: chunked (raw container), and both fail on the previous head. If you would rather keep the Transfer-Encoding case as a strip, I can drop that branch.
Review feedback: the header rules are the same kind of application error as a body. A non-zero Content-Length or a non-empty Transfer-Encoding on a 1xx or 204 response now raises ValueError instead of being stripped. Content-Length: 0 is still dropped, and HEAD/304 semantics are unchanged. Tests cover a 204 with a non-zero Content-Length and a 204 with Transfer-Encoding: chunked through the raw container; both fail on the previous head.
WSGIContaineronly special-cased 304. A WSGI app returning 204 with a body orContent-Length, or 304 with a body, made Tornado write a body for a response that must not have one: 204 producedResponse with code 204 should not have bodyand a malformed HTTP message; 304 raisedHTTPOutputError: Tried to write more data than Content-Length.Treat 1xx/204/304 as no-content:
Content-Length/Transfer-Encodingand send headers only.Content-Lengthbut sends no body.Tests:
python3 -m tornado.test.runtests tornado.test.wsgi_test— 13 tests OK.python3 -m tornado.test.runtests— 1702 tests OK (131 skipped, pre-existing environment skips).Content-Lengthand body (asserts empty body, no container-synthesizedContent-Length/Content-Type), 304 with a body (asserts empty body), 304 withContent-Length, and a 200 control.204sends onlyServer,304may sendContent-Lengthwith no body,200is unchanged, andHEADsends headers only. Keep-alive reuse after these responses serves the next request normally.blackandflake8pass;mypyreports only pre-existingcurl_httpclient.py/optional-module errors, none in the changed files.