@@ -200,7 +200,7 @@ def append(self, item):
200200 # Here, we're testing that methods expecting a body get a
201201 # content-length set to zero if the body is empty (either None or '')
202202 bodies = (None , '' )
203- methods_with_body = ('PUT' , 'POST' , 'PATCH' )
203+ methods_with_body = ('PUT' , 'POST' , 'PATCH' , 'QUERY' )
204204 for method , body in itertools .product (methods_with_body , bodies ):
205205 conn = client .HTTPConnection ('example.com' )
206206 conn .sock = FakeSocket (None )
@@ -554,6 +554,34 @@ def test_invalid_method_names(self):
554554 conn .sock = FakeSocket (None )
555555 conn .request (method = method , url = "/" )
556556
557+ def test_query_request (self ):
558+ # QUERY (RFC 10008) is sent with a body, like PUT/POST/PATCH.
559+ conn = client .HTTPConnection ('example.com' )
560+ conn .sock = FakeSocket (None )
561+ conn .request ('QUERY' , '/contacts' , body = 'name=python' ,
562+ headers = {'Content-Type' : 'application/x-www-form-urlencoded' })
563+ self .assertEqual (conn .sock .data ,
564+ b'QUERY /contacts HTTP/1.1\r \n '
565+ b'Host: example.com\r \n '
566+ b'Accept-Encoding: identity\r \n '
567+ b'Content-Length: 11\r \n '
568+ b'Content-Type: application/x-www-form-urlencoded\r \n '
569+ b'\r \n '
570+ b'name=python' )
571+
572+ def test_query_request_no_body (self ):
573+ # A QUERY without a body still gets Content-Length: 0, since some
574+ # servers respond with 411 otherwise.
575+ conn = client .HTTPConnection ('example.com' )
576+ conn .sock = FakeSocket (None )
577+ conn .request ('QUERY' , '/contacts' )
578+ self .assertEqual (conn .sock .data ,
579+ b'QUERY /contacts HTTP/1.1\r \n '
580+ b'Host: example.com\r \n '
581+ b'Accept-Encoding: identity\r \n '
582+ b'Content-Length: 0\r \n '
583+ b'\r \n ' )
584+
557585
558586class TransferEncodingTest (TestCase ):
559587 expected_body = b"It's just a flesh wound"
0 commit comments