Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send 204 as HTTPError #3360

Open
pawciobiel opened this issue Feb 16, 2024 · 0 comments · May be fixed by #3361
Open

Send 204 as HTTPError #3360

pawciobiel opened this issue Feb 16, 2024 · 0 comments · May be fixed by #3361

Comments

@pawciobiel
Copy link

pawciobiel commented Feb 16, 2024

Occasionally it is useful to send HTTP204 via exception raise HTTPError(204) .
Also when run with python -O assertions are removed causing the check for no content useless.
But the response buffer has value:

[b'<html><title>204: No Content</title><body>204: No Content</body></html>']
Traceback (most recent call last):
  File "/home/pgb/.local/lib/python3.10/site-packages/tornado/web.py", line 1791, in _execute
    self._handle_request_exception(e)
  File "/home/pgb/.local/lib/python3.10/site-packages/tornado/web.py", line 1846, in _handle_request_exception
    self.send_error(e.status_code, exc_info=sys.exc_info())
  File "/home/pgb/.local/lib/python3.10/site-packages/tornado/web.py", line 1298, in send_error
    self.finish()
  File "/home/pgb/.local/lib/python3.10/site-packages/tornado/web.py", line 1219, in finish
    assert not self._write_buffer, (
AssertionError: Cannot send body with 204
pawciobiel added a commit to pawciobiel/tornado that referenced this issue Feb 16, 2024
Change `write_error()` to not send body if
 status code in (204, 304) or (100 <= status code < 200)
 - refactored into `RequestHandler._should_not_send_content(status_code)`
Change `get_arguments()` to raise `ValueError` if `strip` is not boolean
 - as opposed to `AssertionError`.

Fixes tornadoweb#3360
@pawciobiel pawciobiel linked a pull request Feb 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant