Tests: added "Host" and "Connetion" headers where necessary.

Also minor header organizing.
This commit is contained in:
Andrey Zelenkov
2019-02-27 19:15:02 +03:00
parent 379e4c75fd
commit 4de2c8b567
10 changed files with 143 additions and 99 deletions

View File

@@ -23,9 +23,9 @@ class TestUnitAccessLog(unit.TestUnitApplicationPython):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='01234') }, start=True, body='01234')
time.sleep(0.2) time.sleep(0.2)
@@ -34,9 +34,9 @@ class TestUnitAccessLog(unit.TestUnitApplicationPython):
self.search_in_log(r'"POST / HTTP/1.1" 200 5'), 'keepalive 1') self.search_in_log(r'"POST / HTTP/1.1" 200 5'), 'keepalive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
time.sleep(0.2) time.sleep(0.2)

View File

@@ -14,7 +14,8 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -36,7 +37,8 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
'Server-Protocol': 'HTTP/1.1', 'Server-Protocol': 'HTTP/1.1',
'Server-Protocol-Major': '1', 'Server-Protocol-Major': '1',
'Server-Protocol-Minor': '1', 'Server-Protocol-Minor': '1',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, 'headers') }, 'headers')
self.assertEqual(resp['body'], body, 'body') self.assertEqual(resp['body'], body, 'body')
@@ -52,8 +54,8 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
self.load('post_variables') self.load('post_variables')
resp = self.post(headers={ resp = self.post(headers={
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'close' 'Connection': 'close'
}, body='var1=val1&var2=&var3') }, body='var1=val1&var2=&var3')
@@ -74,17 +76,17 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Connection': 'close', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Host': 'localhost' 'Connection': 'close'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
@@ -93,8 +95,8 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo):
self.load('cookies') self.load('cookies')
resp = self.get(headers={ resp = self.get(headers={
'Cookie': 'var1=val1; var2=val2',
'Host': 'localhost', 'Host': 'localhost',
'Cookie': 'var1=val1; var2=val2',
'Connection': 'close' 'Connection': 'close'
}) })

View File

@@ -10,7 +10,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': ' ,' 'Host': 'localhost',
'Custom-Header': ' ,',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value leading sp status') self.assertEqual(resp['status'], 200, 'value leading sp status')
@@ -21,7 +23,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': '\t,' 'Host': 'localhost',
'Custom-Header': '\t,',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value leading htab status') self.assertEqual(resp['status'], 200, 'value leading htab status')
@@ -32,7 +36,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': ', ' 'Host': 'localhost',
'Custom-Header': ', ',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value trailing sp status') self.assertEqual(resp['status'], 200, 'value trailing sp status')
@@ -43,7 +49,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': ',\t' 'Host': 'localhost',
'Custom-Header': ',\t',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value trailing htab status') self.assertEqual(resp['status'], 200, 'value trailing htab status')
@@ -54,7 +62,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': ' , ' 'Host': 'localhost',
'Custom-Header': ' , ',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value both sp status') self.assertEqual(resp['status'], 200, 'value both sp status')
@@ -65,7 +75,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': '\t,\t' 'Host': 'localhost',
'Custom-Header': '\t,\t',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value both htab status') self.assertEqual(resp['status'], 200, 'value both htab status')
@@ -76,7 +88,9 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.load('custom_header') self.load('custom_header')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header': '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~' 'Host': 'localhost',
'Custom-Header': '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 200, 'value chars status') self.assertEqual(resp['status'], 200, 'value chars status')
@@ -113,7 +127,9 @@ Connection: close
self.load('empty') self.load('empty')
resp = self.get(headers={ resp = self.get(headers={
' Custom-Header': 'blah' 'Host': 'localhost',
' Custom-Header': 'blah',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 400, 'field leading sp') self.assertEqual(resp['status'], 400, 'field leading sp')
@@ -122,7 +138,9 @@ Connection: close
self.load('empty') self.load('empty')
resp = self.get(headers={ resp = self.get(headers={
'\tCustom-Header': 'blah' 'Host': 'localhost',
'\tCustom-Header': 'blah',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 400, 'field leading htab') self.assertEqual(resp['status'], 400, 'field leading htab')
@@ -131,7 +149,9 @@ Connection: close
self.load('empty') self.load('empty')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header ': 'blah' 'Host': 'localhost',
'Custom-Header ': 'blah',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 400, 'field trailing sp') self.assertEqual(resp['status'], 400, 'field trailing sp')
@@ -140,7 +160,9 @@ Connection: close
self.load('empty') self.load('empty')
resp = self.get(headers={ resp = self.get(headers={
'Custom-Header\t': 'blah' 'Host': 'localhost',
'Custom-Header\t': 'blah',
'Connection': 'close'
}) })
self.assertEqual(resp['status'], 400, 'field trailing htab') self.assertEqual(resp['status'], 400, 'field trailing htab')
@@ -149,45 +171,45 @@ Connection: close
self.load('empty') self.load('empty')
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost',
'Content-Length': str(2 ** 64), 'Content-Length': str(2 ** 64),
'Connection': 'close', 'Connection': 'close'
'Host': 'localhost'
}, body='X' * 1000)['status'], 400, 'Content-Length big') }, body='X' * 1000)['status'], 400, 'Content-Length big')
def test_http_header_content_length_negative(self): def test_http_header_content_length_negative(self):
self.load('empty') self.load('empty')
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost',
'Content-Length': '-100', 'Content-Length': '-100',
'Connection': 'close', 'Connection': 'close'
'Host': 'localhost'
}, body='X' * 1000)['status'], 400, 'Content-Length negative') }, body='X' * 1000)['status'], 400, 'Content-Length negative')
def test_http_header_content_length_text(self): def test_http_header_content_length_text(self):
self.load('empty') self.load('empty')
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost',
'Content-Length': 'blah', 'Content-Length': 'blah',
'Connection': 'close', 'Connection': 'close'
'Host': 'localhost'
}, body='X' * 1000)['status'], 400, 'Content-Length text') }, body='X' * 1000)['status'], 400, 'Content-Length text')
def test_http_header_content_length_multiple_values(self): def test_http_header_content_length_multiple_values(self):
self.load('empty') self.load('empty')
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost',
'Content-Length': '41, 42', 'Content-Length': '41, 42',
'Connection': 'close', 'Connection': 'close'
'Host': 'localhost'
}, body='X' * 1000)['status'], 400, 'Content-Length multiple value') }, body='X' * 1000)['status'], 400, 'Content-Length multiple value')
def test_http_header_content_length_multiple_fields(self): def test_http_header_content_length_multiple_fields(self):
self.load('empty') self.load('empty')
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost',
'Content-Length': ['41', '42'], 'Content-Length': ['41', '42'],
'Connection': 'close', 'Connection': 'close'
'Host': 'localhost'
}, body='X' * 1000)['status'], 400, 'Content-Length multiple fields') }, body='X' * 1000)['status'], 400, 'Content-Length multiple fields')
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -28,7 +28,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -43,10 +44,11 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
raw_headers = headers.pop('Request-Raw-Headers') raw_headers = headers.pop('Request-Raw-Headers')
self.assertRegex(raw_headers, r'^(?:Host|localhost|Content-Type|' \ self.assertRegex(raw_headers, r'^(?:Host|localhost|Content-Type|' \
'text\/html|Custom-Header|blah|Content-Length|17|,)+$', 'text\/html|Custom-Header|blah|Content-Length|17|Connection|' \
'raw headers') 'close|,)+$', 'raw headers')
self.assertDictEqual(headers, { self.assertDictEqual(headers, {
'Connection': 'close',
'Content-Length': str(len(body)), 'Content-Length': str(len(body)),
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Request-Method': 'POST', 'Request-Method': 'POST',
@@ -91,17 +93,17 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
@@ -142,7 +144,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
resp = self.get(headers={ resp = self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
'X-Remove': 'X-Header' 'X-Remove': 'X-Header',
'Connection': 'close'
}) })
self.assertEqual(resp['headers']['Was-Header'], 'true', 'was header') self.assertEqual(resp['headers']['Was-Header'], 'true', 'was header')
self.assertEqual(resp['headers']['Has-Header'], 'false', 'has header') self.assertEqual(resp['headers']['Has-Header'], 'false', 'has header')
@@ -153,7 +156,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
'X-Remove': 'blah' 'X-Remove': 'blah',
'Connection': 'close'
})['headers']['Has-Header'], 'true', 'remove header nonexisting') })['headers']['Has-Header'], 'true', 'remove header nonexisting')
def test_node_application_update_header(self): def test_node_application_update_header(self):
@@ -194,7 +198,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html' 'Content-Type': 'text/html',
'Connection': 'close'
}, body='callback')['status'], 200, 'promise handler request') }, body='callback')['status'], 200, 'promise handler request')
self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'),
'promise handler') 'promise handler')
@@ -205,7 +210,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'X-Write-Call': '1' 'X-Write-Call': '1',
'Connection': 'close'
}, body='callback')['status'], 200, }, body='callback')['status'], 200,
'promise handler request write after end') 'promise handler request write after end')
@@ -214,7 +220,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.post(headers={ self.assertEqual(self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html' 'Content-Type': 'text/html',
'Connection': 'close'
}, body='end')['status'], 200, 'promise end request') }, body='end')['status'], 200, 'promise end request')
self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'),
'promise end') 'promise end')
@@ -224,7 +231,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.post(headers={ self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html' 'Content-Type': 'text/html',
'Connection': 'close'
}, body='callback1') }, body='callback1')
self.assertTrue(self.waitforfiles(self.testdir + '/node/callback1'), self.assertTrue(self.waitforfiles(self.testdir + '/node/callback1'),
@@ -232,7 +240,8 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.post(headers={ self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html' 'Content-Type': 'text/html',
'Connection': 'close'
}, body='callback2') }, body='callback2')
self.assertTrue(self.waitforfiles(self.testdir + '/node/callback2'), self.assertTrue(self.waitforfiles(self.testdir + '/node/callback2'),
@@ -260,12 +269,14 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
'X-Header': 'length' 'X-Header': 'length',
'Connection': 'close'
})['headers']['X-Has-Header'], 'false', 'has header length') })['headers']['X-Has-Header'], 'false', 'has header length')
self.assertEqual(self.get(headers={ self.assertEqual(self.get(headers={
'Host': 'localhost', 'Host': 'localhost',
'X-Header': 'Date' 'X-Header': 'Date',
'Connection': 'close'
})['headers']['X-Has-Header'], 'false', 'has header date') })['headers']['X-Has-Header'], 'false', 'has header date')
def test_node_application_write_multiple(self): def test_node_application_write_multiple(self):

View File

@@ -14,7 +14,8 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -30,6 +31,7 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl):
'date header') 'date header')
self.assertDictEqual(headers, { self.assertDictEqual(headers, {
'Connection': 'close',
'Content-Length': str(len(body)), 'Content-Length': str(len(body)),
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Request-Method': 'POST', 'Request-Method': 'POST',
@@ -170,17 +172,17 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl):
self.load('variables') self.load('variables')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')

View File

@@ -19,7 +19,8 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -39,6 +40,7 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
headers.pop('Content-type') headers.pop('Content-type')
self.assertDictEqual(headers, { self.assertDictEqual(headers, {
'Connection': 'close',
'Content-Length': str(len(body)), 'Content-Length': str(len(body)),
'Request-Method': 'POST', 'Request-Method': 'POST',
'Request-Uri': '/', 'Request-Uri': '/',
@@ -96,17 +98,17 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')

View File

@@ -15,7 +15,8 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -31,6 +32,7 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
'date header') 'date header')
self.assertDictEqual(headers, { self.assertDictEqual(headers, {
'Connection': 'close',
'Content-Length': str(len(body)), 'Content-Length': str(len(body)),
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Request-Method': 'POST', 'Request-Method': 'POST',
@@ -90,9 +92,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.load('ctx_iter_atexit') self.load('ctx_iter_atexit')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, body='0123456789') }, body='0123456789')
self.assertEqual(resp['status'], 200, 'ctx iter status') self.assertEqual(resp['status'], 200, 'ctx iter status')
@@ -114,17 +116,17 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
@@ -138,9 +140,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
for i in range(conns): for i in range(conns):
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body=body) }, start=True, body=body)
self.assertEqual(resp['body'], body, 'keep-alive open') self.assertEqual(resp['body'], body, 'keep-alive open')
@@ -153,9 +155,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
for i in range(conns): for i in range(conns):
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, sock=socks[i], body=body) }, start=True, sock=socks[i], body=body)
self.assertEqual(resp['body'], body, 'keep-alive request') self.assertEqual(resp['body'], body, 'keep-alive request')
@@ -166,9 +168,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
for i in range(conns): for i in range(conns):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=socks[i], body=body) }, sock=socks[i], body=body)
self.assertEqual(resp['body'], body, 'keep-alive close') self.assertEqual(resp['body'], body, 'keep-alive close')
@@ -183,9 +185,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
body = '0123456789' body = '0123456789'
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body=body) }, start=True, body=body)
self.assertEqual(resp['body'], body, 'reconfigure 2 keep-alive 1') self.assertEqual(resp['body'], body, 'reconfigure 2 keep-alive 1')
@@ -193,9 +195,9 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython):
self.load('empty') self.load('empty')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, sock=sock, body=body) }, start=True, sock=sock, body=body)
self.assertEqual(resp['status'], 200, 'reconfigure 2 keep-alive 2') self.assertEqual(resp['status'], 200, 'reconfigure 2 keep-alive 2')

View File

@@ -14,7 +14,8 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby):
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost', 'Host': 'localhost',
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Custom-Header': 'blah' 'Custom-Header': 'blah',
'Connection': 'close'
}, body=body) }, body=body)
self.assertEqual(resp['status'], 200, 'status') self.assertEqual(resp['status'], 200, 'status')
@@ -30,6 +31,7 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby):
'date header') 'date header')
self.assertDictEqual(headers, { self.assertDictEqual(headers, {
'Connection': 'close',
'Content-Length': str(len(body)), 'Content-Length': str(len(body)),
'Content-Type': 'text/html', 'Content-Type': 'text/html',
'Request-Method': 'POST', 'Request-Method': 'POST',
@@ -286,17 +288,17 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby):
self.load('mirror') self.load('mirror')
(resp, sock) = self.post(headers={ (resp, sock) = self.post(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789' * 500) }, start=True, body='0123456789' * 500)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
resp = self.post(headers={ resp = self.post(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')

View File

@@ -118,6 +118,7 @@ Connection: close
Host: localhost Host: localhost
Content-Type: text/html Content-Type: text/html
Content-Length: %d Content-Length: %d
Connection: close
""" % data_len + ('X' * data_len) """ % data_len + ('X' * data_len)
@@ -140,15 +141,15 @@ Content-Length: %d
self.conf({'http': { 'idle_timeout': 2 }}, 'settings') self.conf({'http': { 'idle_timeout': 2 }}, 'settings')
(resp, sock) = self.get(headers={ (resp, sock) = self.get(headers={
'Connection': 'keep-alive', 'Host': 'localhost',
'Host': 'localhost' 'Connection': 'keep-alive'
}, start=True) }, start=True)
time.sleep(3) time.sleep(3)
resp = self.get(headers={ resp = self.get(headers={
'Connection': 'close', 'Host': 'localhost',
'Host': 'localhost' 'Connection': 'close'
}, sock=sock) }, sock=sock)
self.assertEqual(resp['status'], 408, 'status idle timeout') self.assertEqual(resp['status'], 408, 'status idle timeout')

View File

@@ -313,8 +313,8 @@ basicConstraints = critical,CA:TRUE""" % {
self.certificate() self.certificate()
(resp, sock) = self.get(headers={ (resp, sock) = self.get(headers={
'Connection': 'keep-alive', 'Host': 'localhost',
'Host': 'localhost' 'Connection': 'keep-alive'
}, start=True) }, start=True)
self.assertEqual(resp['status'], 200, 'initial status') self.assertEqual(resp['status'], 200, 'initial status')
@@ -334,17 +334,17 @@ basicConstraints = critical,CA:TRUE""" % {
self.add_tls(application='mirror') self.add_tls(application='mirror')
(resp, sock) = self.post_ssl(headers={ (resp, sock) = self.post_ssl(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789') }, start=True, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keepalive 1') self.assertEqual(resp['body'], '0123456789', 'keepalive 1')
resp = self.post_ssl(headers={ resp = self.post_ssl(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['body'], '0123456789', 'keepalive 2') self.assertEqual(resp['body'], '0123456789', 'keepalive 2')
@@ -358,8 +358,8 @@ basicConstraints = critical,CA:TRUE""" % {
self.add_tls() self.add_tls()
(resp, sock) = self.get_ssl(headers={ (resp, sock) = self.get_ssl(headers={
'Connection': 'keep-alive', 'Host': 'localhost',
'Host': 'localhost' 'Connection': 'keep-alive'
}, start=True) }, start=True)
self.conf({ self.conf({
@@ -369,8 +369,8 @@ basicConstraints = critical,CA:TRUE""" % {
try: try:
resp = self.get_ssl(headers={ resp = self.get_ssl(headers={
'Connection': 'close', 'Host': 'localhost',
'Host': 'localhost' 'Connection': 'close'
}, sock=sock) }, sock=sock)
except: except:
resp = None resp = None
@@ -397,9 +397,9 @@ basicConstraints = critical,CA:TRUE""" % {
self.add_tls(application='mirror') self.add_tls(application='mirror')
(resp, sock) = self.post_ssl(headers={ (resp, sock) = self.post_ssl(headers={
'Host': 'localhost',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, start=True, body='0123456789') }, start=True, body='0123456789')
app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0] app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]
@@ -410,9 +410,9 @@ basicConstraints = critical,CA:TRUE""" % {
'#)(\d+)#\d+ "mirror" application started')) '#)(\d+)#\d+ "mirror" application started'))
resp = self.post_ssl(headers={ resp = self.post_ssl(headers={
'Host': 'localhost',
'Connection': 'close', 'Connection': 'close',
'Content-Type': 'text/html', 'Content-Type': 'text/html'
'Host': 'localhost'
}, sock=sock, body='0123456789') }, sock=sock, body='0123456789')
self.assertEqual(resp['status'], 200, 'application respawn status') self.assertEqual(resp['status'], 200, 'application respawn status')