[Python-checkins] bpo-39509: Update HTTP status code to follow IANA (GH-18294)

Dong-hee Na webhook-mailer at python.org
Sat Mar 14 10:12:05 EDT 2020


https://github.com/python/cpython/commit/da52be47690da0d9f78d0dce9ee5c3e4dbef49e1
commit: da52be47690da0d9f78d0dce9ee5c3e4dbef49e1
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-03-14T16:12:01+02:00
summary:

bpo-39509: Update HTTP status code to follow IANA (GH-18294)

Add status codes 103 EARLY_HINTS and 425 TOO_EARLY.

files:
A Misc/NEWS.d/next/Library/2020-02-01-00-03-06.bpo-39509.-YxUSf.rst
M Doc/library/http.rst
M Doc/whatsnew/3.9.rst
M Lib/http/__init__.py
M Lib/test/test_httplib.py

diff --git a/Doc/library/http.rst b/Doc/library/http.rst
index 0e3441cbcb718..f120ada2091b5 100644
--- a/Doc/library/http.rst
+++ b/Doc/library/http.rst
@@ -62,6 +62,7 @@ Code    Enum Name                           Details
 ``100`` ``CONTINUE``                        HTTP/1.1 :rfc:`7231`, Section 6.2.1
 ``101`` ``SWITCHING_PROTOCOLS``             HTTP/1.1 :rfc:`7231`, Section 6.2.2
 ``102`` ``PROCESSING``                      WebDAV :rfc:`2518`, Section 10.1
+``103`` ``EARLY_HINTS``                     An HTTP Status Code for Indicating Hints :rfc:`8297`
 ``200`` ``OK``                              HTTP/1.1 :rfc:`7231`, Section 6.3.1
 ``201`` ``CREATED``                         HTTP/1.1 :rfc:`7231`, Section 6.3.2
 ``202`` ``ACCEPTED``                        HTTP/1.1 :rfc:`7231`, Section 6.3.3
@@ -102,6 +103,7 @@ Code    Enum Name                           Details
 ``422`` ``UNPROCESSABLE_ENTITY``            WebDAV :rfc:`4918`, Section 11.2
 ``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`
 ``426`` ``UPGRADE_REQUIRED``                HTTP/1.1 :rfc:`7231`, Section 6.5.15
 ``428`` ``PRECONDITION_REQUIRED``           Additional HTTP Status Codes :rfc:`6585`
 ``429`` ``TOO_MANY_REQUESTS``               Additional HTTP Status Codes :rfc:`6585`
@@ -130,3 +132,6 @@ equal to the constant name (i.e. ``http.HTTPStatus.OK`` is also available as
 
 .. versionadded:: 3.8
    Added ``451 UNAVAILABLE_FOR_LEGAL_REASONS`` status code.
+
+.. versionadded:: 3.9
+   Added ``103 EARLY_HINTS`` and ``425 TOO_EARLY`` status codes.
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index fc91870739c09..b078e7917765b 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -232,6 +232,12 @@ Added a new function :func:`gc.is_finalized` to check if an object has been
 finalized by the garbage collector. (Contributed by Pablo Galindo in
 :issue:`39322`.)
 
+http
+----
+
+HTTP status codes ``103 EARLY_HINTS`` and ``425 TOO_EARLY`` are added to
+:class:`http.HTTPStatus`. (Contributed by Dong-hee Na in :issue:`39509`.)
+
 imaplib
 -------
 
diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py
index 350afe77926b0..c8498be0de20d 100644
--- a/Lib/http/__init__.py
+++ b/Lib/http/__init__.py
@@ -17,6 +17,8 @@ class HTTPStatus(IntEnum):
         * RFC 2774: An HTTP Extension Framework
         * RFC 7725: An HTTP Status Code to Report Legal Obstacles
         * RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)
+        * RFC 8297: An HTTP Status Code for Indicating Hints
+        * RFC 8470: Using Early Data in HTTP
     """
     def __new__(cls, value, phrase, description=''):
         obj = int.__new__(cls, value)
@@ -31,6 +33,7 @@ def __new__(cls, value, phrase, description=''):
     SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
             'Switching to new protocol; obey Upgrade header')
     PROCESSING = 102, 'Processing'
+    EARLY_HINTS = 103, 'Early Hints'
 
     # success
     OK = 200, 'OK', 'Request fulfilled, document follows'
@@ -105,6 +108,7 @@ def __new__(cls, value, phrase, description=''):
     UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity'
     LOCKED = 423, 'Locked'
     FAILED_DEPENDENCY = 424, 'Failed Dependency'
+    TOO_EARLY = 425, 'Too Early'
     UPGRADE_REQUIRED = 426, 'Upgrade Required'
     PRECONDITION_REQUIRED = (428, 'Precondition Required',
         'The origin server requires the request to be conditional')
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index e1aa41421febf..95eca7e00a029 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1440,6 +1440,8 @@ def test_client_constants(self):
             'INSUFFICIENT_STORAGE',
             'NOT_EXTENDED',
             'NETWORK_AUTHENTICATION_REQUIRED',
+            'EARLY_HINTS',
+            'TOO_EARLY'
         ]
         for const in expected:
             with self.subTest(constant=const):
diff --git a/Misc/NEWS.d/next/Library/2020-02-01-00-03-06.bpo-39509.-YxUSf.rst b/Misc/NEWS.d/next/Library/2020-02-01-00-03-06.bpo-39509.-YxUSf.rst
new file mode 100644
index 0000000000000..9969556e0304c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-02-01-00-03-06.bpo-39509.-YxUSf.rst
@@ -0,0 +1,2 @@
+HTTP status codes ``103 EARLY_HINTS`` and ``425 TOO_EARLY`` are added to
+:class:`http.HTTPStatus`. Patch by Dong-hee Na.



More information about the Python-checkins mailing list