Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51b2ed5

Browse files
committed
#14809: Add HTTP status codes from RFC 6585 to http.server and http.client
Patch by EungJun Yi.
1 parent 313fbe2 commit 51b2ed5

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

Doc/library/http.client.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ and also the following constants for integer status codes:
339339
| :const:`UPGRADE_REQUIRED` | ``426`` | HTTP Upgrade to TLS, |
340340
| | | :rfc:`2817`, Section 6 |
341341
+------------------------------------------+---------+-----------------------------------------------------------------------+
342+
| :const:`PRECONDITION_REQUIRED` | ``428`` | Additional HTTP Status Codes, |
343+
| | | :rfc:`6585`, Section 3 |
344+
+------------------------------------------+---------+-----------------------------------------------------------------------+
345+
| :const:`TOO_MANY_REQUESTS` | ``429`` | Additional HTTP Status Codes, |
346+
| | | :rfc:`6585`, Section 4 |
347+
+------------------------------------------+---------+-----------------------------------------------------------------------+
348+
| :const:`REQUEST_HEADER_FIELDS_TOO_LARGE` | ``431`` | Additional HTTP Status Codes, |
349+
| | | :rfc:`6585`, Section 5 |
350+
+------------------------------------------+---------+-----------------------------------------------------------------------+
342351
| :const:`INTERNAL_SERVER_ERROR` | ``500`` | HTTP/1.1, `RFC 2616, Section |
343352
| | | 10.5.1 |
344353
| | | <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1>`_ |
@@ -369,6 +378,12 @@ and also the following constants for integer status codes:
369378
| :const:`NOT_EXTENDED` | ``510`` | An HTTP Extension Framework, |
370379
| | | :rfc:`2774`, Section 7 |
371380
+------------------------------------------+---------+-----------------------------------------------------------------------+
381+
| :const:`NETWORK_AUTHENTICATION_REQUIRED` | ``511`` | Additional HTTP Status Codes, |
382+
| | | :rfc:`6585`, Section 6 |
383+
+------------------------------------------+---------+-----------------------------------------------------------------------+
384+
385+
.. versionchanged:: 3.3
386+
Added codes ``428``, ``429``, ``431`` and ``511`` from :rfc:`6585`.
372387

373388

374389
.. data:: responses

Lib/http/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
LOCKED = 423
142142
FAILED_DEPENDENCY = 424
143143
UPGRADE_REQUIRED = 426
144+
PRECONDITION_REQUIRED = 428
145+
TOO_MANY_REQUESTS = 429
146+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
144147

145148
# server error
146149
INTERNAL_SERVER_ERROR = 500
@@ -151,6 +154,7 @@
151154
HTTP_VERSION_NOT_SUPPORTED = 505
152155
INSUFFICIENT_STORAGE = 507
153156
NOT_EXTENDED = 510
157+
NETWORK_AUTHENTICATION_REQUIRED = 511
154158

155159
# Mapping status codes to official W3C names
156160
responses = {
@@ -192,13 +196,17 @@
192196
415: 'Unsupported Media Type',
193197
416: 'Requested Range Not Satisfiable',
194198
417: 'Expectation Failed',
199+
428: 'Precondition Required',
200+
429: 'Too Many Requests',
201+
431: 'Request Header Fields Too Large',
195202

196203
500: 'Internal Server Error',
197204
501: 'Not Implemented',
198205
502: 'Bad Gateway',
199206
503: 'Service Unavailable',
200207
504: 'Gateway Timeout',
201208
505: 'HTTP Version Not Supported',
209+
511: 'Network Authentication Required',
202210
}
203211

204212
# maximal amount of data to read at one time in _safe_read

Lib/http/server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def address_string(self):
573573

574574
# Table mapping response codes to messages; entries have the
575575
# form {code: (shortmessage, longmessage)}.
576-
# See RFC 2616.
576+
# See RFC 2616 and 6585.
577577
responses = {
578578
100: ('Continue', 'Request received, please continue'),
579579
101: ('Switching Protocols',
@@ -628,6 +628,12 @@ def address_string(self):
628628
'Cannot satisfy request range.'),
629629
417: ('Expectation Failed',
630630
'Expect condition could not be satisfied.'),
631+
428: ('Precondition Required',
632+
'The origin server requires the request to be conditional.'),
633+
429: ('Too Many Requests', 'The user has sent too many requests '
634+
'in a given amount of time ("rate limiting").'),
635+
431: ('Request Header Fields Too Large', 'The server is unwilling to '
636+
'process the request because its header fields are too large.'),
631637

632638
500: ('Internal Server Error', 'Server got itself in trouble'),
633639
501: ('Not Implemented',
@@ -638,6 +644,8 @@ def address_string(self):
638644
504: ('Gateway Timeout',
639645
'The gateway server did not receive a timely response'),
640646
505: ('HTTP Version Not Supported', 'Cannot fulfill request.'),
647+
511: ('Network Authentication Required',
648+
'The client needs to authenticate to gain network access.'),
641649
}
642650

643651

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ Florent Xicluna
11291129
Hirokazu Yamamoto
11301130
Ka-Ping Yee
11311131
Jason Yeo
1132+
EungJun Yi
11321133
Bob Yodlowski
11331134
Danny Yoo
11341135
George Yoshida

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Core and Builtins
3434
Library
3535
-------
3636

37+
- Issue #14809: Add HTTP status codes introduced by RFC 6585 to http.server
38+
and http.client. Patch by EungJun Yi.
39+
3740
- Issue #14777: tkinter may return undecoded UTF-8 bytes as a string when
3841
accessing the Tk clipboard. Modify clipboad_get() to first request type
3942
UTF8_STRING when no specific type is requested in an X11 windowing

0 commit comments

Comments
 (0)