From 748c501c16aea2b90f49b2ef76d73ef1e127215b Mon Sep 17 00:00:00 2001 From: Milkey Mouse Date: Thu, 26 Nov 2015 17:54:52 -0800 Subject: [PATCH 1/4] Add HTTP status codes to web_exceptions.py See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes --- aiohttp/web_exceptions.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index dfa0027f24a..d0a0df50b64 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -253,6 +253,26 @@ class HTTPExpectationFailed(HTTPClientError): status_code = 417 +class HTTPMisdirectedRequest(HTTPClientError): + status_code = 421 + + +class HTTPUpgradeRequired(HTTPClientError): + status_code = 426 + + +class HTTPPreconditionRequired(HTTPClientError): + status_code = 428 + + +class HTTPTooManyRequests(HTTPClientError): + status_code = 429 + + +class HTTPRequestHeaderFieldsTooLarge(HTTPClientError): + status_code = 431 + + ############################################################ # 5xx Server Error ############################################################ @@ -291,3 +311,13 @@ class HTTPGatewayTimeout(HTTPServerError): class HTTPVersionNotSupported(HTTPServerError): status_code = 505 + + +class HTTPVariantAlsoNegotiates(HTTPServerError): + status_code = 506 + +class HTTPNotExtended(HTTPServerError): + status_code = 510 + +class HTTPNetworkAuthenticationRequired(HTTPServerError): + status_code = 511 From cbe073e3cdadfbf08a9ace49ef97c8be7437d343 Mon Sep 17 00:00:00 2001 From: Milkey Mouse Date: Thu, 26 Nov 2015 17:59:17 -0800 Subject: [PATCH 2/4] Add new status codes to __all__ list --- aiohttp/web_exceptions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index d0a0df50b64..75989b0cbfd 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -39,6 +39,11 @@ 'HTTPUnsupportedMediaType', 'HTTPRequestRangeNotSatisfiable', 'HTTPExpectationFailed', + 'HTTPMisdirectedRequest', + 'HTTPUpgradeRequired', + 'HTTPPreconditionRequired', + 'HTTPTooManyRequests', + 'HTTPRequestHeaderFieldsTooLarge', 'HTTPServerError', 'HTTPInternalServerError', 'HTTPNotImplemented', @@ -46,6 +51,9 @@ 'HTTPServiceUnavailable', 'HTTPGatewayTimeout', 'HTTPVersionNotSupported', + 'HTTPVariantAlsoNegotiates', + 'HTTPNotExtended', + 'HTTPNetworkAuthenticationRequired', ) From 79f9efdb2052dfd2c8b8b8645c31a743d2011d5a Mon Sep 17 00:00:00 2001 From: Milkey Mouse Date: Thu, 26 Nov 2015 18:34:16 -0800 Subject: [PATCH 3/4] Add new status codes to docs --- docs/web.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/web.rst b/docs/web.rst index 4d3f1edf6f5..8692494f440 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -513,6 +513,11 @@ HTTP Exception hierarchy chart:: * 415 - HTTPUnsupportedMediaType * 416 - HTTPRequestRangeNotSatisfiable * 417 - HTTPExpectationFailed + * 421 - HTTPMisdirectedRequest + * 426 - HTTPUpgradeRequired + * 428 - HTTPPreconditionRequired + * 429 - HTTPTooManyRequests + * 431 - HTTPRequestHeaderFieldsTooLarge HTTPServerError * 500 - HTTPInternalServerError * 501 - HTTPNotImplemented @@ -520,6 +525,9 @@ HTTP Exception hierarchy chart:: * 503 - HTTPServiceUnavailable * 504 - HTTPGatewayTimeout * 505 - HTTPVersionNotSupported + * 506 - HTTPVariantAlsoNegotiates + * 510 - HTTPNotExtended + * 511 - HTTPNetworkAuthenticationRequired All HTTP exceptions have the same constructor:: From 93cbf200e6da128837e06a8b94859d0e87588607 Mon Sep 17 00:00:00 2001 From: Milkey Mouse Date: Thu, 26 Nov 2015 18:40:46 -0800 Subject: [PATCH 4/4] Fix formatting for status codes One too few lines on two of the classes --- aiohttp/web_exceptions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index 75989b0cbfd..0a59032a63d 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -324,8 +324,10 @@ class HTTPVersionNotSupported(HTTPServerError): class HTTPVariantAlsoNegotiates(HTTPServerError): status_code = 506 + class HTTPNotExtended(HTTPServerError): status_code = 510 + class HTTPNetworkAuthenticationRequired(HTTPServerError): status_code = 511