Skip to content

Commit c1fc922

Browse files
committed
more tests
1 parent 2a4ad49 commit c1fc922

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/test/test_httplib.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

532560
class TransferEncodingTest(TestCase):
533561
expected_body = b"It's just a flesh wound"

0 commit comments

Comments
 (0)