From 944e2de8939334be567342840769ec85b95910ab Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 10:20:35 +0900 Subject: [PATCH 1/8] Update HTTP status codes in httplib package to match rfc9110 --- Doc/library/http.rst | 8 ++++---- Lib/http/__init__.py | 6 +++--- Lib/test/test_httplib.py | 10 +++++----- .../2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst | 2 ++ 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst diff --git a/Doc/library/http.rst b/Doc/library/http.rst index 5e1912716e5319..7d353331667e0b 100644 --- a/Doc/library/http.rst +++ b/Doc/library/http.rst @@ -80,7 +80,7 @@ Code Enum Name Details ``304`` ``NOT_MODIFIED`` HTTP/1.1 :rfc:`7232`, Section 4.1 ``305`` ``USE_PROXY`` HTTP/1.1 :rfc:`7231`, Section 6.4.5 ``307`` ``TEMPORARY_REDIRECT`` HTTP/1.1 :rfc:`7231`, Section 6.4.7 -``308`` ``PERMANENT_REDIRECT`` Permanent Redirect :rfc:`7238`, Section 3 (Experimental) +``308`` ``PERMANENT_REDIRECT`` HTTP Semantics :rfc:`9110`, Section 15.4.9 ``400`` ``BAD_REQUEST`` HTTP/1.1 :rfc:`7231`, Section 6.5.1 ``401`` ``UNAUTHORIZED`` HTTP/1.1 Authentication :rfc:`7235`, Section 3.1 ``402`` ``PAYMENT_REQUIRED`` HTTP/1.1 :rfc:`7231`, Section 6.5.2 @@ -94,14 +94,14 @@ Code Enum Name Details ``410`` ``GONE`` HTTP/1.1 :rfc:`7231`, Section 6.5.9 ``411`` ``LENGTH_REQUIRED`` HTTP/1.1 :rfc:`7231`, Section 6.5.10 ``412`` ``PRECONDITION_FAILED`` HTTP/1.1 :rfc:`7232`, Section 4.2 -``413`` ``REQUEST_ENTITY_TOO_LARGE`` HTTP/1.1 :rfc:`7231`, Section 6.5.11 +``413`` ``CONTENT_TOO_LARGE`` HTTP Semantics :rfc:`9110`, Section 15.5.14 ``414`` ``REQUEST_URI_TOO_LONG`` HTTP/1.1 :rfc:`7231`, Section 6.5.12 ``415`` ``UNSUPPORTED_MEDIA_TYPE`` HTTP/1.1 :rfc:`7231`, Section 6.5.13 ``416`` ``REQUESTED_RANGE_NOT_SATISFIABLE`` HTTP/1.1 Range Requests :rfc:`7233`, Section 4.4 ``417`` ``EXPECTATION_FAILED`` HTTP/1.1 :rfc:`7231`, Section 6.5.14 ``418`` ``IM_A_TEAPOT`` HTCPCP/1.0 :rfc:`2324`, Section 2.3.2 -``421`` ``MISDIRECTED_REQUEST`` HTTP/2 :rfc:`7540`, Section 9.1.2 -``422`` ``UNPROCESSABLE_ENTITY`` WebDAV :rfc:`4918`, Section 11.2 +``421`` ``MISDIRECTED_REQUEST`` HTTP Semantics :rfc:`9110`, Section 15.5.20 +``422`` ``UNPROCESSABLE_CONTENT`` HTTP Semantics :rfc:`9110`, Section 15.5.21 ``423`` ``LOCKED`` WebDAV :rfc:`4918`, Section 11.3 ``424`` ``FAILED_DEPENDENCY`` WebDAV :rfc:`4918`, Section 11.4 ``425`` ``TOO_EARLY`` Using Early Data in HTTP :rfc:`8470` diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py index e093a1fec4dffc..8c535c8e837c4b 100644 --- a/Lib/http/__init__.py +++ b/Lib/http/__init__.py @@ -115,8 +115,8 @@ def is_server_error(self): 'Client must specify Content-Length') PRECONDITION_FAILED = (412, 'Precondition Failed', 'Precondition in headers is false') - REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large', - 'Entity is too large') + CONTENT_TOO_LARGE = (413, 'Content Too Large', + 'Content is too large') REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', 'URI is too long') UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', @@ -130,7 +130,7 @@ def is_server_error(self): 'Server refuses to brew coffee because it is a teapot.') MISDIRECTED_REQUEST = (421, 'Misdirected Request', 'Server is not able to produce a response') - UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity' + UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content' LOCKED = 423, 'Locked' FAILED_DEPENDENCY = 424, 'Failed Dependency' TOO_EARLY = 425, 'Too Early' diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 9ff6afcbadec54..187f69452e2bfe 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -633,8 +633,8 @@ def is_server_error(self): 'Client must specify Content-Length') PRECONDITION_FAILED = (412, 'Precondition Failed', 'Precondition in headers is false') - REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large', - 'Entity is too large') + CONTENT_TOO_LARGE = (413, 'Content Too Large', + 'Content is too large') REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', 'URI is too long') UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', @@ -648,7 +648,7 @@ def is_server_error(self): 'Server refuses to brew coffee because it is a teapot.') MISDIRECTED_REQUEST = (421, 'Misdirected Request', 'Server is not able to produce a response') - UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity' + UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content' LOCKED = 423, 'Locked' FAILED_DEPENDENCY = 424, 'Failed Dependency' TOO_EARLY = 425, 'Too Early' @@ -1688,14 +1688,14 @@ def test_client_constants(self): 'GONE', 'LENGTH_REQUIRED', 'PRECONDITION_FAILED', - 'REQUEST_ENTITY_TOO_LARGE', + 'CONTENT_TOO_LARGE', 'REQUEST_URI_TOO_LONG', 'UNSUPPORTED_MEDIA_TYPE', 'REQUESTED_RANGE_NOT_SATISFIABLE', 'EXPECTATION_FAILED', 'IM_A_TEAPOT', 'MISDIRECTED_REQUEST', - 'UNPROCESSABLE_ENTITY', + 'UNPROCESSABLE_CONTENT', 'LOCKED', 'FAILED_DEPENDENCY', 'UPGRADE_REQUIRED', diff --git a/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst b/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst new file mode 100644 index 00000000000000..35092aca58d407 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst @@ -0,0 +1,2 @@ +Update HTTP status codes in httplib package to match rfc9110. Patch by +Yeojin Kim From e4bdf25c763527674c07e5628c6b9ae536c5cfe1 Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 10:33:29 +0900 Subject: [PATCH 2/8] Update docstring --- Lib/http/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py index 8c535c8e837c4b..e25c116e68b6a6 100644 --- a/Lib/http/__init__.py +++ b/Lib/http/__init__.py @@ -22,6 +22,7 @@ class HTTPStatus: * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) * RFC 8297: An HTTP Status Code for Indicating Hints * RFC 8470: Using Early Data in HTTP + * RFC 9110: HTTP Semantics """ def __new__(cls, value, phrase, description=''): obj = int.__new__(cls, value) From 14bc8ea8a837988a0d81810ac59e3adc8b4d8504 Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 10:34:42 +0900 Subject: [PATCH 3/8] Fix typo --- .../next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst b/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst index 35092aca58d407..2d9ddae8aebf6a 100644 --- a/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst +++ b/Misc/NEWS.d/next/Library/2023-03-10-10-20-01.gh-issue-102247.uvsFqi.rst @@ -1,2 +1,2 @@ -Update HTTP status codes in httplib package to match rfc9110. Patch by +Update HTTP status codes in http package to match rfc9110. Patch by Yeojin Kim From 999e811f43bcd55afe23d3a1c01333f5dac55281 Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 18:11:45 +0900 Subject: [PATCH 4/8] Add legacy constants --- Lib/http/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py index e25c116e68b6a6..556c32320b3f64 100644 --- a/Lib/http/__init__.py +++ b/Lib/http/__init__.py @@ -118,6 +118,7 @@ def is_server_error(self): 'Precondition in headers is false') CONTENT_TOO_LARGE = (413, 'Content Too Large', 'Content is too large') + REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE # for backward compatibility REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', 'URI is too long') UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', @@ -132,6 +133,7 @@ def is_server_error(self): MISDIRECTED_REQUEST = (421, 'Misdirected Request', 'Server is not able to produce a response') UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content' + UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT # for backward compatibility LOCKED = 423, 'Locked' FAILED_DEPENDENCY = 424, 'Failed Dependency' TOO_EARLY = 425, 'Too Early' From 77576988ae5aecefcf07300b10ff43854dda781c Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 18:29:58 +0900 Subject: [PATCH 5/8] Add docs --- Doc/library/http.rst | 5 +++++ Doc/whatsnew/3.12.rst | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Doc/library/http.rst b/Doc/library/http.rst index 7d353331667e0b..a0db5d7b25094a 100644 --- a/Doc/library/http.rst +++ b/Doc/library/http.rst @@ -137,6 +137,11 @@ equal to the constant name (i.e. ``http.HTTPStatus.OK`` is also available as .. versionadded:: 3.9 Added ``103 EARLY_HINTS``, ``418 IM_A_TEAPOT`` and ``425 TOO_EARLY`` status codes. +.. versionadded:: 3.12 + Updated ``413 REQUEST_ENTITY_TOO_LARGE`` and ``422 UNPROCESSABLE_ENTITY`` + to ``413 CONTENT_TOO_LARGE`` and ``422 UNPROCESSABLE_CONTENT``. Backward compatibility + of previous status codes in :mod:`http` module is preserved. + HTTP status category -------------------- diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index d982cb62ec2f4e..a79ee105baec36 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -372,6 +372,14 @@ sys with contributions from Gregory P. Smith [Google] and Mark Shannon in :gh:`96123`.) +http +---- + +* Updated ``413 REQUEST_ENTITY_TOO_LARGE`` and ``422 UNPROCESSABLE_ENTITY`` + to ``413 CONTENT_TOO_LARGE`` and ``422 UNPROCESSABLE_CONTENT``. This is + for applying :rfc:`9110`. Backward compatibility of previous status codes in + :mod:`http` module is preserved. (Contributed by Yeojin Kim in :gh:`102570`.) + Optimizations ============= From 0273b0db3d928f695e62f69f3203be9b4bec6c49 Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 19:40:02 +0900 Subject: [PATCH 6/8] Restore for backward compatibility --- Lib/test/test_httplib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 187f69452e2bfe..1d23ba1150dbf6 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -635,6 +635,7 @@ def is_server_error(self): 'Precondition in headers is false') CONTENT_TOO_LARGE = (413, 'Content Too Large', 'Content is too large') + REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE # for backward compatibility REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', 'URI is too long') UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', @@ -649,6 +650,7 @@ def is_server_error(self): MISDIRECTED_REQUEST = (421, 'Misdirected Request', 'Server is not able to produce a response') UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content' + UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT # for backward compatibility LOCKED = 423, 'Locked' FAILED_DEPENDENCY = 424, 'Failed Dependency' TOO_EARLY = 425, 'Too Early' @@ -1689,6 +1691,7 @@ def test_client_constants(self): 'LENGTH_REQUIRED', 'PRECONDITION_FAILED', 'CONTENT_TOO_LARGE', + 'REQUEST_ENTITY_TOO_LARGE', 'REQUEST_URI_TOO_LONG', 'UNSUPPORTED_MEDIA_TYPE', 'REQUESTED_RANGE_NOT_SATISFIABLE', @@ -1696,6 +1699,7 @@ def test_client_constants(self): 'IM_A_TEAPOT', 'MISDIRECTED_REQUEST', 'UNPROCESSABLE_CONTENT', + 'UNPROCESSABLE_ENTITY', 'LOCKED', 'FAILED_DEPENDENCY', 'UPGRADE_REQUIRED', From 90bf421f78d9f008f95e915eefa7b4d3b771cd5b Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Fri, 10 Mar 2023 21:34:43 +0900 Subject: [PATCH 7/8] Use _simple_enum to equal HTTPStatus --- Lib/test/test_httplib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 1d23ba1150dbf6..c7c76d49fb1c2c 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -525,7 +525,8 @@ def test_dir_with_added_behavior_on_status(self): self.assertTrue({'description', 'name', 'phrase', 'value'} <= set(dir(HTTPStatus(404)))) def test_simple_httpstatus(self): - class CheckedHTTPStatus(enum.IntEnum): + @enum._simple_enum(enum.IntEnum) + class CheckedHTTPStatus: """HTTP status codes and reason phrases Status codes from the following RFCs are all observed: From 8d7018150e14b065330941f3155bf0665beb22be Mon Sep 17 00:00:00 2001 From: Yeojin Kim Date: Sat, 11 Mar 2023 06:57:26 +0900 Subject: [PATCH 8/8] Revert "Use _simple_enum to equal HTTPStatus" This reverts commit 90bf421f78d9f008f95e915eefa7b4d3b771cd5b. --- Lib/test/test_httplib.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index c7c76d49fb1c2c..1d23ba1150dbf6 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -525,8 +525,7 @@ def test_dir_with_added_behavior_on_status(self): self.assertTrue({'description', 'name', 'phrase', 'value'} <= set(dir(HTTPStatus(404)))) def test_simple_httpstatus(self): - @enum._simple_enum(enum.IntEnum) - class CheckedHTTPStatus: + class CheckedHTTPStatus(enum.IntEnum): """HTTP status codes and reason phrases Status codes from the following RFCs are all observed: