https://github.com/python/cpython/commit/646673c05fe879b1dd2417a9845db33cad1deb90
commit: 646673c05fe879b1dd2417a9845db33cad1deb90
branch: main
author: Michiel W. Beijen <[email protected]>
committer: orsenthil <[email protected]>
date: 2026-11-14T05:42:07-08:00
summary:

gh-153309: Add HTTP QUERY method (RFC 10008) to http library (#155786)

Add HTTP QUERY method (RFC 10008) to http library

Closes #153309

files:
A Misc/NEWS.d/next/Library/2026-07-08-09-05-01.gh-issue-153309.g94LSO.rst
M Doc/library/http.client.rst
M Doc/library/http.rst
M Doc/whatsnew/3.16.rst
M Lib/http/__init__.py
M Lib/http/client.py
M Lib/test/test_httplib.py
M Lib/wsgiref/validate.py

diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst
index 20fd357c56ac3ef..50a11ff18ab9bb2 100644
--- a/Doc/library/http.client.rst
+++ b/Doc/library/http.client.rst
@@ -312,7 +312,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 <file object>`, the Content-Length header is
    set to its length.  Any other type of *body* (files
@@ -369,6 +369,9 @@ HTTPConnection Objects
       *continue_timeout* value must be greater than zero, otherwise
       :exc:`ValueError` is raised.
 
+   .. versionchanged:: next
+      ``QUERY`` was added to the methods that expect a body.
+
 .. method:: HTTPConnection.getresponse(support_continue=False)
 
    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
        <HTTPMethod.PATCH>,
        <HTTPMethod.POST>,
        <HTTPMethod.PUT>,
+       <HTTPMethod.QUERY>,
        <HTTPMethod.TRACE>]
 
 .. _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 f86a6ec69172d8a..a7972d23e435afd 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -508,6 +508,13 @@ gzip
   (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`.)
+
+
 http.client
 -----------
 
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 864ffc12b21e8a1..c05d7d933028430 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -183,7 +183,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 04fcd0c883e638f..eb604bd2c4421be 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -200,7 +200,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)
@@ -554,6 +554,34 @@ def test_invalid_method_names(self):
                 conn.sock = FakeSocket(None)
                 conn.request(method=method, url="/")
 
+    def test_query_request(self):
+        # QUERY (RFC 10008) is sent with a body, like PUT/POST/PATCH.
+        conn = client.HTTPConnection('example.com')
+        conn.sock = FakeSocket(None)
+        conn.request('QUERY', '/contacts', body='name=python',
+                     headers={'Content-Type': 
'application/x-www-form-urlencoded'})
+        self.assertEqual(conn.sock.data,
+                         b'QUERY /contacts HTTP/1.1\r\n'
+                         b'Host: example.com\r\n'
+                         b'Accept-Encoding: identity\r\n'
+                         b'Content-Length: 11\r\n'
+                         b'Content-Type: application/x-www-form-urlencoded\r\n'
+                         b'\r\n'
+                         b'name=python')
+
+    def test_query_request_no_body(self):
+        # A QUERY without a body still gets Content-Length: 0, since some
+        # servers respond with 411 otherwise.
+        conn = client.HTTPConnection('example.com')
+        conn.sock = FakeSocket(None)
+        conn.request('QUERY', '/contacts')
+        self.assertEqual(conn.sock.data,
+                         b'QUERY /contacts HTTP/1.1\r\n'
+                         b'Host: example.com\r\n'
+                         b'Accept-Encoding: identity\r\n'
+                         b'Content-Length: 0\r\n'
+                         b'\r\n')
+
 
 class TransferEncodingTest(TestCase):
     expected_body = b"It's just a flesh wound"
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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to