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

feat (status_codes): update HTTP status constants wrt RFC 9110 #2330

Merged
merged 14 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ Note that this example assumes that the
msg = ('The size of the request is too large. The body must not '
'exceed ' + str(limit) + ' bytes in length.')

raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request body is too large', description=msg)

return hook
Expand Down Expand Up @@ -830,7 +830,7 @@ Here's the ASGI version of the app from above. Note that it uses the
msg = ('The size of the request is too large. The body must not '
'exceed ' + str(limit) + ' bytes in length.')

raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request body is too large', description=msg)

return hook
Expand Down
1 change: 1 addition & 0 deletions docs/_newsfragments/2330.newandimproved.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: Replaced :class:`~falcon.HTTPPayloadTooLarge` with :class:`~falcon.HTTPContentTooLarge` to align with the updated class name.
2 changes: 1 addition & 1 deletion docs/api/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Predefined Errors
.. autoclass:: falcon.HTTPPreconditionFailed
:members:

.. autoclass:: falcon.HTTPPayloadTooLarge
.. autoclass:: falcon.HTTPContentTooLarge
:members:

.. autoclass:: falcon.HTTPUriTooLong
Expand Down
2 changes: 1 addition & 1 deletion docs/api/status.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ HTTPStatus
HTTP_410 = '410 Gone'
HTTP_411 = '411 Length Required'
HTTP_412 = '412 Precondition Failed'
HTTP_413 = '413 Payload Too Large'
HTTP_413 = '413 Content Too Large'
HTTP_414 = '414 URI Too Long'
HTTP_415 = '415 Unsupported Media Type'
HTTP_416 = '416 Range Not Satisfiable'
Expand Down
2 changes: 1 addition & 1 deletion docs/changes/2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Fixed
- The :meth:`~falcon.testing.TestClient.simulate_request` method now forces
header values to `str` on Python 2 as required by PEP-3333.
- The ``HTTPRequestEntityTooLarge`` class was renamed to
:class:`~falcon.HTTPPayloadTooLarge` and the reason phrase was updated
:class:`~falcon.HTTPContentTooLarge` and the reason phrase was updated
vytas7 marked this conversation as resolved.
Show resolved Hide resolved
per RFC 7231.
- The :class:`falcon.CaseInsensitiveDict` class now inherits from
:class:`collections.abc.MutableMapping` under Python 3, instead of
Expand Down
2 changes: 1 addition & 1 deletion examples/things_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def hook(req, resp, resource, params):
'exceed ' + str(limit) + ' bytes in length.'
)

raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request body is too large', description=msg
)

Expand Down
2 changes: 1 addition & 1 deletion examples/things_advanced_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def hook(req, resp, resource, params):
'exceed ' + str(limit) + ' bytes in length.'
)

raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request body is too large', description=msg
)

Expand Down
6 changes: 3 additions & 3 deletions falcon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
'HTTPNotAcceptable',
'HTTPNotFound',
'HTTPNotImplemented',
'HTTPPayloadTooLarge',
'HTTPContentTooLarge',
'HTTPPreconditionFailed',
'HTTPPreconditionRequired',
'HTTPRangeNotSatisfiable',
Expand Down Expand Up @@ -355,6 +355,7 @@
from falcon.errors import HTTPBadGateway
from falcon.errors import HTTPBadRequest
from falcon.errors import HTTPConflict
from falcon.errors import HTTPContentTooLarge
from falcon.errors import HTTPFailedDependency
from falcon.errors import HTTPForbidden
from falcon.errors import HTTPGatewayTimeout
Expand All @@ -373,7 +374,6 @@
from falcon.errors import HTTPNotAcceptable
from falcon.errors import HTTPNotFound
from falcon.errors import HTTPNotImplemented
from falcon.errors import HTTPPayloadTooLarge
from falcon.errors import HTTPPreconditionFailed
from falcon.errors import HTTPPreconditionRequired
from falcon.errors import HTTPRangeNotSatisfiable
Expand Down Expand Up @@ -530,6 +530,7 @@
from falcon.status_codes import HTTP_BAD_GATEWAY
from falcon.status_codes import HTTP_BAD_REQUEST
from falcon.status_codes import HTTP_CONFLICT
from falcon.status_codes import HTTP_CONTENT_TOO_LARGE
vytas7 marked this conversation as resolved.
Show resolved Hide resolved
from falcon.status_codes import HTTP_CONTINUE
from falcon.status_codes import HTTP_CREATED
from falcon.status_codes import HTTP_EARLY_HINTS
Expand Down Expand Up @@ -568,7 +569,6 @@
from falcon.status_codes import HTTP_PRECONDITION_REQUIRED
from falcon.status_codes import HTTP_PROCESSING
from falcon.status_codes import HTTP_PROXY_AUTHENTICATION_REQUIRED
from falcon.status_codes import HTTP_REQUEST_ENTITY_TOO_LARGE
from falcon.status_codes import HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
from falcon.status_codes import HTTP_REQUEST_TIMEOUT
from falcon.status_codes import HTTP_REQUEST_URI_TOO_LONG
Expand Down
6 changes: 3 additions & 3 deletions falcon/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def on_get(self, req, resp):
'HTTPNotAcceptable',
'HTTPNotFound',
'HTTPNotImplemented',
'HTTPPayloadTooLarge',
'HTTPContentTooLarge',
'HTTPPreconditionFailed',
'HTTPPreconditionRequired',
'HTTPRangeNotSatisfiable',
Expand Down Expand Up @@ -952,8 +952,8 @@ def __init__(
)


class HTTPPayloadTooLarge(HTTPError):
"""413 Payload Too Large.
class HTTPContentTooLarge(HTTPError):
vytas7 marked this conversation as resolved.
Show resolved Hide resolved
"""413 Content Too Large.

The server is refusing to process a request because the request
payload is larger than the server is willing or able to process.
Expand Down
5 changes: 3 additions & 2 deletions falcon/status_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
HTTP_LENGTH_REQUIRED: Final[str] = HTTP_411
HTTP_412: Final[str] = '412 Precondition Failed'
HTTP_PRECONDITION_FAILED: Final[str] = HTTP_412
HTTP_413: Final[str] = '413 Payload Too Large'
HTTP_413: Final[str] = '413 Content Too Large'
HTTP_CONTENT_TOO_LARGE: Final[str] = HTTP_413
HTTP_REQUEST_ENTITY_TOO_LARGE: Final[str] = HTTP_413
HTTP_414: Final[str] = '414 URI Too Long'
HTTP_REQUEST_URI_TOO_LONG: Final[str] = HTTP_414
Expand Down Expand Up @@ -330,6 +331,7 @@
'HTTP_BAD_GATEWAY',
'HTTP_BAD_REQUEST',
'HTTP_CONFLICT',
'HTTP_CONTENT_TOO_LARGE',
'HTTP_CONTINUE',
'HTTP_CREATED',
'HTTP_EARLY_HINTS',
Expand Down Expand Up @@ -369,7 +371,6 @@
'HTTP_PROCESSING',
'HTTP_PROXY_AUTHENTICATION_REQUIRED',
'HTTP_REQUESTED_RANGE_NOT_SATISFIABLE',
'HTTP_REQUEST_ENTITY_TOO_LARGE',
'HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE',
'HTTP_REQUEST_TIMEOUT',
'HTTP_REQUEST_URI_TOO_LONG',
Expand Down
12 changes: 6 additions & 6 deletions tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(falcon.HTTPGone, status.HTTP_410),
(falcon.HTTPLengthRequired, status.HTTP_411),
(falcon.HTTPPreconditionFailed, status.HTTP_412),
(falcon.HTTPPayloadTooLarge, status.HTTP_413),
(falcon.HTTPContentTooLarge, status.HTTP_413),
(falcon.HTTPUriTooLong, status.HTTP_414),
(falcon.HTTPUnsupportedMediaType, status.HTTP_415),
(falcon.HTTPUnprocessableEntity, status.HTTP_422),
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_with_default_title_and_desc_args(err, title, args):
falcon.HTTPGone,
falcon.HTTPLengthRequired,
falcon.HTTPPreconditionFailed,
falcon.HTTPPayloadTooLarge,
falcon.HTTPContentTooLarge,
falcon.HTTPUriTooLong,
falcon.HTTPUnsupportedMediaType,
falcon.HTTPUnprocessableEntity,
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_with_title_desc_and_headers(err):
falcon.HTTPGone,
falcon.HTTPLengthRequired,
falcon.HTTPPreconditionFailed,
falcon.HTTPPayloadTooLarge,
falcon.HTTPContentTooLarge,
falcon.HTTPUriTooLong,
falcon.HTTPUnsupportedMediaType,
falcon.HTTPUnprocessableEntity,
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_args_kw_only(err, args):
[
falcon.HTTPServiceUnavailable,
falcon.HTTPTooManyRequests,
falcon.HTTPPayloadTooLarge,
falcon.HTTPContentTooLarge,
],
)
def test_with_retry_after(err):
Expand All @@ -217,7 +217,7 @@ def test_with_retry_after(err):
[
falcon.HTTPServiceUnavailable,
falcon.HTTPTooManyRequests,
falcon.HTTPPayloadTooLarge,
falcon.HTTPContentTooLarge,
],
)
def test_with_retry_after_and_headers(err):
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_custom_400(err, args, title, desc):
'a, b',
True,
),
(falcon.HTTPPayloadTooLarge, 'Retry-After', 'retry_after', 123, '123', False),
(falcon.HTTPContentTooLarge, 'Retry-After', 'retry_after', 123, '123', False),
(
falcon.HTTPRangeNotSatisfiable,
'Content-Range',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_httperror.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def on_get(self, req, resp):

class RequestEntityTooLongResource:
def on_get(self, req, resp):
raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request Rejected', description='Request Body Too Large'
)

Expand All @@ -182,7 +182,7 @@ def __init__(self, retry_after):
self.retry_after = retry_after

def on_get(self, req, resp):
raise falcon.HTTPPayloadTooLarge(
raise falcon.HTTPContentTooLarge(
title='Request Rejected',
description='Request Body Too Large',
retry_after=self.retry_after,
Expand Down
Loading