diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst index 98ea09d8f72d8b6..12868c18c416512 100644 --- a/Doc/library/http.client.rst +++ b/Doc/library/http.client.rst @@ -289,7 +289,7 @@ HTTPConnection Objects but there is a request body, one of those header fields will be added automatically. If *body* is ``None``, the Content-Length header is set to ``0`` for - methods that expect a body (``PUT``, ``POST``, and ``PATCH``). If + methods that expect a body (``PUT``, ``POST``, ``PATCH``, and ``QUERY``). If *body* is a string or a bytes-like object that is not also a :term:`file `, the Content-Length header is set to its length. Any other type of *body* (files @@ -335,6 +335,9 @@ HTTPConnection Objects No attempt is made to determine the Content-Length for file objects. + .. versionchanged:: next + ``QUERY`` was added to the methods that expect a body. + .. method:: HTTPConnection.getresponse() Should be called after a request is sent to get the response from the server. diff --git a/Doc/library/http.rst b/Doc/library/http.rst index 43a801416e24f99..2520c9718aed6c6 100644 --- a/Doc/library/http.rst +++ b/Doc/library/http.rst @@ -194,6 +194,7 @@ Property Indicates that Details , , , + , ] .. _http-methods: @@ -217,4 +218,5 @@ Method Enum Name Details ``OPTIONS`` ``OPTIONS`` HTTP Semantics :rfc:`9110`, Section 9.3.7 ``TRACE`` ``TRACE`` HTTP Semantics :rfc:`9110`, Section 9.3.8 ``PATCH`` ``PATCH`` HTTP/1.1 :rfc:`5789` +``QUERY`` ``QUERY`` The HTTP QUERY Method :rfc:`10008` =========== =================================== ================================================================== diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index e871ad822bbcedc..6145d71499140e7 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -229,6 +229,13 @@ gzip which is passed on to the constructor of the :class:`~gzip.GzipFile` class. (Contributed by Marin Misur in :gh:`91372`.) + +http +---- + +* Add the ``QUERY`` HTTP method (:rfc:`10008`) to :class:`~http.HTTPMethod`. + (Contributed by Michiel W. Beijen in :gh:`153309`.) + io -- diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py index 691b4a9a367bd0f..219b3d1355b7294 100644 --- a/Lib/http/__init__.py +++ b/Lib/http/__init__.py @@ -192,6 +192,7 @@ class HTTPMethod: * RFC 9110: HTTP Semantics, obsoletes 7231, which obsoleted 2616 * RFC 5789: PATCH Method for HTTP + * RFC 10008: The HTTP QUERY Method """ def __new__(cls, value, description): obj = str.__new__(cls, value) @@ -210,4 +211,5 @@ def __repr__(self): PATCH = 'PATCH', 'Apply partial modifications to a target.' POST = 'POST', 'Perform target-specific processing with the request payload.' PUT = 'PUT', 'Replace the target with the request payload.' + QUERY = 'QUERY', 'Request that the target process the request payload in a safe and idempotent manner.' TRACE = 'TRACE', 'Perform a message loop-back test along the path to the target.' diff --git a/Lib/http/client.py b/Lib/http/client.py index 7ef99e7201c005c..aafd3c55166d94f 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -167,7 +167,7 @@ # We always set the Content-Length header for these methods because some # servers will otherwise respond with a 411 -_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'} +_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT', 'QUERY'} def _encode(data, name='data'): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 5b1d6e0aa520794..abd21ef215a27c1 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -179,7 +179,7 @@ def append(self, item): # Here, we're testing that methods expecting a body get a # content-length set to zero if the body is empty (either None or '') bodies = (None, '') - methods_with_body = ('PUT', 'POST', 'PATCH') + methods_with_body = ('PUT', 'POST', 'PATCH', 'QUERY') for method, body in itertools.product(methods_with_body, bodies): conn = client.HTTPConnection('example.com') conn.sock = FakeSocket(None) diff --git a/Lib/wsgiref/validate.py b/Lib/wsgiref/validate.py index 1a1853cd63a0d2a..cc572e8a179d1eb 100644 --- a/Lib/wsgiref/validate.py +++ b/Lib/wsgiref/validate.py @@ -334,7 +334,7 @@ def check_environ(environ): # @@: these need filling out: if environ['REQUEST_METHOD'] not in ( - 'GET', 'HEAD', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE', 'TRACE'): + 'GET', 'HEAD', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE', 'QUERY', 'TRACE'): warnings.warn( "Unknown REQUEST_METHOD: %r" % environ['REQUEST_METHOD'], WSGIWarning) diff --git a/Misc/NEWS.d/next/Library/2026-07-08-09-05-01.gh-issue-153309.g94LSO.rst b/Misc/NEWS.d/next/Library/2026-07-08-09-05-01.gh-issue-153309.g94LSO.rst new file mode 100644 index 000000000000000..9245c1442b06f87 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-08-09-05-01.gh-issue-153309.g94LSO.rst @@ -0,0 +1 @@ +:mod:`http`: Add the HTTP QUERY method (:rfc:`10008`) to :class:`~http.HTTPMethod`.