feat(status_codes) Handle 451 Unavailable For Legal Reasons
See https://en.wikipedia.org/wiki/HTTP_451 for details.
This commit is contained in:
@@ -37,4 +37,5 @@ Predefined Errors
|
|||||||
HTTPMethodNotAllowed, HTTPNotAcceptable, HTTPConflict,
|
HTTPMethodNotAllowed, HTTPNotAcceptable, HTTPConflict,
|
||||||
HTTPLengthRequired, HTTPPreconditionFailed, HTTPUnsupportedMediaType,
|
HTTPLengthRequired, HTTPPreconditionFailed, HTTPUnsupportedMediaType,
|
||||||
HTTPRangeNotSatisfiable, HTTPUnprocessableEntity, HTTPTooManyRequests,
|
HTTPRangeNotSatisfiable, HTTPUnprocessableEntity, HTTPTooManyRequests,
|
||||||
HTTPInternalServerError, HTTPBadGateway, HTTPServiceUnavailable
|
HTTPUnavailableForLegalReasons, HTTPInternalServerError,
|
||||||
|
HTTPBadGateway, HTTPServiceUnavailable
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ string objects that must be created when preparing responses.
|
|||||||
HTTP_PRECONDITION_REQUIRED = HTTP_428
|
HTTP_PRECONDITION_REQUIRED = HTTP_428
|
||||||
HTTP_TOO_MANY_REQUESTS = HTTP_429
|
HTTP_TOO_MANY_REQUESTS = HTTP_429
|
||||||
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = HTTP_431
|
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = HTTP_431
|
||||||
|
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = HTTP_451
|
||||||
|
|
||||||
HTTP_400 = '400 Bad Request'
|
HTTP_400 = '400 Bad Request'
|
||||||
HTTP_401 = '401 Unauthorized' # <-- Really means "unauthenticated"
|
HTTP_401 = '401 Unauthorized' # <-- Really means "unauthenticated"
|
||||||
@@ -125,6 +126,7 @@ string objects that must be created when preparing responses.
|
|||||||
HTTP_428 = '428 Precondition Required'
|
HTTP_428 = '428 Precondition Required'
|
||||||
HTTP_429 = '429 Too Many Requests'
|
HTTP_429 = '429 Too Many Requests'
|
||||||
HTTP_431 = '431 Request Header Fields Too Large'
|
HTTP_431 = '431 Request Header Fields Too Large'
|
||||||
|
HTTP_451 = '451 Unavailable For Legal Reasons'
|
||||||
|
|
||||||
5xx Server Error
|
5xx Server Error
|
||||||
----------------
|
----------------
|
||||||
|
|||||||
@@ -361,6 +361,26 @@ class HTTPTooManyRequests(HTTPError):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPUnavailableForLegalReasons(OptionalRepresentation, HTTPError):
|
||||||
|
"""451 Unavailable For Legal Reasons.
|
||||||
|
|
||||||
|
This status code indicates that the server is denying access to the
|
||||||
|
resource as a consequence of a legal demand.
|
||||||
|
|
||||||
|
See also:
|
||||||
|
https://datatracker.ietf.org/doc/draft-ietf-httpbis-legally-restricted-status/
|
||||||
|
|
||||||
|
Args:
|
||||||
|
title (str): Error title (e.g., 'Legal reason: <reason>').
|
||||||
|
kwargs (optional): Same as for ``HTTPError``.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, title, **kwargs):
|
||||||
|
super(HTTPUnavailableForLegalReasons, self).__init__(status.HTTP_451,
|
||||||
|
title, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class HTTPInternalServerError(HTTPError):
|
class HTTPInternalServerError(HTTPError):
|
||||||
"""500 Internal Server Error.
|
"""500 Internal Server Error.
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ HTTP_429 = '429 Too Many Requests'
|
|||||||
HTTP_TOO_MANY_REQUESTS = HTTP_429
|
HTTP_TOO_MANY_REQUESTS = HTTP_429
|
||||||
HTTP_431 = '431 Request Header Fields Too Large'
|
HTTP_431 = '431 Request Header Fields Too Large'
|
||||||
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = HTTP_431
|
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = HTTP_431
|
||||||
|
HTTP_451 = '451 Unavailable For Legal Reasons'
|
||||||
|
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = HTTP_451
|
||||||
|
|
||||||
HTTP_500 = '500 Internal Server Error'
|
HTTP_500 = '500 Internal Server Error'
|
||||||
HTTP_INTERNAL_SERVER_ERROR = HTTP_500
|
HTTP_INTERNAL_SERVER_ERROR = HTTP_500
|
||||||
|
|||||||
@@ -773,5 +773,7 @@ class TestHTTPError(testing.TestBase):
|
|||||||
self._misc_test(falcon.HTTPUnsupportedMediaType, falcon.HTTP_415,
|
self._misc_test(falcon.HTTPUnsupportedMediaType, falcon.HTTP_415,
|
||||||
needs_title=False)
|
needs_title=False)
|
||||||
self._misc_test(falcon.HTTPUnprocessableEntity, falcon.HTTP_422)
|
self._misc_test(falcon.HTTPUnprocessableEntity, falcon.HTTP_422)
|
||||||
|
self._misc_test(falcon.HTTPUnavailableForLegalReasons, falcon.HTTP_451,
|
||||||
|
needs_title=False)
|
||||||
self._misc_test(falcon.HTTPInternalServerError, falcon.HTTP_500)
|
self._misc_test(falcon.HTTPInternalServerError, falcon.HTTP_500)
|
||||||
self._misc_test(falcon.HTTPBadGateway, falcon.HTTP_502)
|
self._misc_test(falcon.HTTPBadGateway, falcon.HTTP_502)
|
||||||
|
|||||||
Reference in New Issue
Block a user