@@ -179,7 +179,7 @@ def append(self, item):
179179 # Here, we're testing that methods expecting a body get a
180180 # content-length set to zero if the body is empty (either None or '')
181181 bodies = (None , '' )
182- methods_with_body = ('PUT' , 'POST' , 'PATCH' )
182+ methods_with_body = ('PUT' , 'POST' , 'PATCH' , 'QUERY' )
183183 for method , body in itertools .product (methods_with_body , bodies ):
184184 conn = client .HTTPConnection ('example.com' )
185185 conn .sock = FakeSocket (None )
@@ -528,6 +528,34 @@ def test_invalid_method_names(self):
528528 conn .sock = FakeSocket (None )
529529 conn .request (method = method , url = "/" )
530530
531+ def test_query_request (self ):
532+ # QUERY (RFC 10008) is sent with a body, like PUT/POST/PATCH.
533+ conn = client .HTTPConnection ('example.com' )
534+ conn .sock = FakeSocket (None )
535+ conn .request ('QUERY' , '/contacts' , body = 'name=python' ,
536+ headers = {'Content-Type' : 'application/x-www-form-urlencoded' })
537+ self .assertEqual (conn .sock .data ,
538+ b'QUERY /contacts HTTP/1.1\r \n '
539+ b'Host: example.com\r \n '
540+ b'Accept-Encoding: identity\r \n '
541+ b'Content-Length: 11\r \n '
542+ b'Content-Type: application/x-www-form-urlencoded\r \n '
543+ b'\r \n '
544+ b'name=python' )
545+
546+ def test_query_request_no_body (self ):
547+ # A QUERY without a body still gets Content-Length: 0, since some
548+ # servers respond with 411 otherwise.
549+ conn = client .HTTPConnection ('example.com' )
550+ conn .sock = FakeSocket (None )
551+ conn .request ('QUERY' , '/contacts' )
552+ self .assertEqual (conn .sock .data ,
553+ b'QUERY /contacts HTTP/1.1\r \n '
554+ b'Host: example.com\r \n '
555+ b'Accept-Encoding: identity\r \n '
556+ b'Content-Length: 0\r \n '
557+ b'\r \n ' )
558+
531559
532560class TransferEncodingTest (TestCase ):
533561 expected_body = b"It's just a flesh wound"
0 commit comments