Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_httpservers.BaseHTTPRequestHandlerTestCase Class Reference

List of all members.

Public Member Functions

def setUp
def send_typical_request
def verify_get_called
def verify_expected_headers
def verify_http_server_response
def test_http_1_1
def test_http_1_0
def test_http_0_9
def test_with_continue_1_0
def test_with_continue_1_1
def test_header_buffering
def test_header_unbuffered_when_continue
def test_with_continue_rejected
def test_request_length
def test_header_length

Public Attributes

 handler

Static Public Attributes

tuple HTTPResponseMatch = re.compile(b'HTTP/1.[0-9]+ 200 OK')

Detailed Description

Test the functionality of the BaseHTTPServer.

   Test the support for the Expect 100-continue header.

Definition at line 464 of file test_httpservers.py.


Member Function Documentation

Definition at line 475 of file test_httpservers.py.

00475 
00476     def send_typical_request(self, message):
00477         input = BytesIO(message)
00478         output = BytesIO()
00479         self.handler.rfile = input
00480         self.handler.wfile = output
00481         self.handler.handle_one_request()
00482         output.seek(0)
00483         return output.readlines()

Here is the caller graph for this function:

Definition at line 472 of file test_httpservers.py.

00472 
00473     def setUp (self):
00474         self.handler = SocketlessRequestHandler()

Here is the caller graph for this function:

Definition at line 530 of file test_httpservers.py.

00530 
00531     def test_header_buffering(self):
00532 
00533         def _readAndReseek(f):
00534             pos = f.tell()
00535             f.seek(0)
00536             data = f.read()
00537             f.seek(pos)
00538             return data
00539 
00540         input = BytesIO(b'GET / HTTP/1.1\r\n\r\n')
00541         output = BytesIO()
00542         self.handler.rfile = input
00543         self.handler.wfile = output
00544         self.handler.request_version = 'HTTP/1.1'
00545 
00546         self.handler.send_header('Foo', 'foo')
00547         self.handler.send_header('bar', 'bar')
00548         self.assertEqual(_readAndReseek(output), b'')
00549         self.handler.end_headers()
00550         self.assertEqual(_readAndReseek(output),
00551                          b'Foo: foo\r\nbar: bar\r\n\r\n')

Here is the call graph for this function:

Definition at line 592 of file test_httpservers.py.

00592 
00593     def test_header_length(self):
00594         # Issue #6791: same for headers
00595         result = self.send_typical_request(
00596             b'GET / HTTP/1.1\r\nX-Foo: bar' + b'r' * 65537 + b'\r\n\r\n')
00597         self.assertEqual(result[0], b'HTTP/1.1 400 Line too long\r\n')
00598         self.assertFalse(self.handler.get_called)

Here is the call graph for this function:

Definition at line 552 of file test_httpservers.py.

00552 
00553     def test_header_unbuffered_when_continue(self):
00554 
00555         def _readAndReseek(f):
00556             pos = f.tell()
00557             f.seek(0)
00558             data = f.read()
00559             f.seek(pos)
00560             return data
00561 
00562         input = BytesIO(b'GET / HTTP/1.1\r\nExpect: 100-continue\r\n\r\n')
00563         output = BytesIO()
00564         self.handler.rfile = input
00565         self.handler.wfile = output
00566         self.handler.request_version = 'HTTP/1.1'
00567 
00568         self.handler.handle_one_request()
00569         self.assertNotEqual(_readAndReseek(output), b'')
00570         result = _readAndReseek(output).split(b'\r\n')
00571         self.assertEqual(result[0], b'HTTP/1.1 100 Continue')
00572         self.assertEqual(result[1], b'HTTP/1.1 200 OK')

Here is the call graph for this function:

Definition at line 509 of file test_httpservers.py.

00509 
00510     def test_http_0_9(self):
00511         result = self.send_typical_request(b'GET / HTTP/0.9\r\n\r\n')
00512         self.assertEqual(len(result), 1)
00513         self.assertEqual(result[0], b'<html><body>Data</body></html>\r\n')
00514         self.verify_get_called()

Here is the call graph for this function:

Definition at line 502 of file test_httpservers.py.

00502 
00503     def test_http_1_0(self):
00504         result = self.send_typical_request(b'GET / HTTP/1.0\r\n\r\n')
00505         self.verify_http_server_response(result[0])
00506         self.verify_expected_headers(result[1:-1])
00507         self.verify_get_called()
00508         self.assertEqual(result[-1], b'<html><body>Data</body></html>\r\n')

Here is the call graph for this function:

Definition at line 495 of file test_httpservers.py.

00495 
00496     def test_http_1_1(self):
00497         result = self.send_typical_request(b'GET / HTTP/1.1\r\n\r\n')
00498         self.verify_http_server_response(result[0])
00499         self.verify_expected_headers(result[1:-1])
00500         self.verify_get_called()
00501         self.assertEqual(result[-1], b'<html><body>Data</body></html>\r\n')

Here is the call graph for this function:

Definition at line 585 of file test_httpservers.py.

00585 
00586     def test_request_length(self):
00587         # Issue #10714: huge request lines are discarded, to avoid Denial
00588         # of Service attacks.
00589         result = self.send_typical_request(b'GET ' + b'x' * 65537)
00590         self.assertEqual(result[0], b'HTTP/1.1 414 Request-URI Too Long\r\n')
00591         self.assertFalse(self.handler.get_called)

Here is the call graph for this function:

Definition at line 515 of file test_httpservers.py.

00515 
00516     def test_with_continue_1_0(self):
00517         result = self.send_typical_request(b'GET / HTTP/1.0\r\nExpect: 100-continue\r\n\r\n')
00518         self.verify_http_server_response(result[0])
00519         self.verify_expected_headers(result[1:-1])
00520         self.verify_get_called()
00521         self.assertEqual(result[-1], b'<html><body>Data</body></html>\r\n')

Here is the call graph for this function:

Definition at line 522 of file test_httpservers.py.

00522 
00523     def test_with_continue_1_1(self):
00524         result = self.send_typical_request(b'GET / HTTP/1.1\r\nExpect: 100-continue\r\n\r\n')
00525         self.assertEqual(result[0], b'HTTP/1.1 100 Continue\r\n')
00526         self.assertEqual(result[1], b'HTTP/1.1 200 OK\r\n')
00527         self.verify_expected_headers(result[2:-1])
00528         self.verify_get_called()
00529         self.assertEqual(result[-1], b'<html><body>Data</body></html>\r\n')

Here is the call graph for this function:

Definition at line 573 of file test_httpservers.py.

00573 
00574     def test_with_continue_rejected(self):
00575         usual_handler = self.handler        # Save to avoid breaking any subsequent tests.
00576         self.handler = RejectingSocketlessRequestHandler()
00577         result = self.send_typical_request(b'GET / HTTP/1.1\r\nExpect: 100-continue\r\n\r\n')
00578         self.assertEqual(result[0], b'HTTP/1.1 417 Expectation Failed\r\n')
00579         self.verify_expected_headers(result[1:-1])
00580         # The expect handler should short circuit the usual get method by
00581         # returning false here, so get_called should be false
00582         self.assertFalse(self.handler.get_called)
00583         self.assertEqual(sum(r == b'Connection: close\r\n' for r in result[1:-1]), 1)
00584         self.handler = usual_handler        # Restore to avoid breaking any subsequent tests.

Here is the call graph for this function:

Definition at line 487 of file test_httpservers.py.

00487 
00488     def verify_expected_headers(self, headers):
00489         for fieldName in b'Server: ', b'Date: ', b'Content-Type: ':
00490             self.assertEqual(sum(h.startswith(fieldName) for h in headers), 1)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 484 of file test_httpservers.py.

00484 
00485     def verify_get_called(self):
00486         self.assertTrue(self.handler.get_called)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 491 of file test_httpservers.py.

00491 
00492     def verify_http_server_response(self, response):
00493         match = self.HTTPResponseMatch.search(response)
00494         self.assertTrue(match is not None)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 473 of file test_httpservers.py.

Definition at line 470 of file test_httpservers.py.


The documentation for this class was generated from the following file: