Test and fix for weird 'Unexpected EOF' error discovered through use. wsgi_test.py may not be the best place for this test but at least it's there.
This commit is contained in:
@@ -537,6 +537,13 @@ class GreenSSL(GreenSocket):
|
|||||||
self.sock = self
|
self.sock = self
|
||||||
|
|
||||||
read = read
|
read = read
|
||||||
|
|
||||||
|
def sendall(self, data):
|
||||||
|
# overriding sendall because ssl sockets behave badly when asked to
|
||||||
|
# send empty strings; 'normal' sockets don't have a problem
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
super(GreenSSL, self).sendall(data)
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
try:
|
try:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""\
|
"""\
|
||||||
@file httpd_test.py
|
@file wsgi_test.py
|
||||||
@author Donovan Preston
|
@author Donovan Preston
|
||||||
|
|
||||||
Copyright (c) 2007, Linden Research, Inc.
|
Copyright (c) 2007, Linden Research, Inc.
|
||||||
@@ -43,7 +43,7 @@ def hello_world(env, start_response):
|
|||||||
if env['PATH_INFO'] == 'notexist':
|
if env['PATH_INFO'] == 'notexist':
|
||||||
start_response('404 Not Found', [('Content-type', 'text/plain')])
|
start_response('404 Not Found', [('Content-type', 'text/plain')])
|
||||||
return ["not found"]
|
return ["not found"]
|
||||||
|
|
||||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||||
return ["hello world"]
|
return ["hello world"]
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
def test_001_server(self):
|
def test_001_server(self):
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||||
result = fd.read()
|
result = fd.read()
|
||||||
@@ -135,7 +135,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
def test_002_keepalive(self):
|
def test_002_keepalive(self):
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||||
read_http(sock)
|
read_http(sock)
|
||||||
@@ -147,7 +147,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
# This should go in greenio_test
|
# This should go in greenio_test
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||||
cancel = api.exc_after(1, RuntimeError)
|
cancel = api.exc_after(1, RuntimeError)
|
||||||
@@ -189,7 +189,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
status = result.split(' ')[1]
|
status = result.split(' ')[1]
|
||||||
self.assertEqual(status, '414')
|
self.assertEqual(status, '414')
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def test_007_get_arg(self):
|
def test_007_get_arg(self):
|
||||||
# define a new handler that does a get_arg as well as a read_body
|
# define a new handler that does a get_arg as well as a read_body
|
||||||
def new_app(env, start_response):
|
def new_app(env, start_response):
|
||||||
@@ -201,24 +201,24 @@ class TestHttpd(tests.TestCase):
|
|||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
request = '\r\n'.join((
|
request = '\r\n'.join((
|
||||||
'POST / HTTP/1.0',
|
'POST / HTTP/1.0',
|
||||||
'Host: localhost',
|
'Host: localhost',
|
||||||
'Content-Length: 3',
|
'Content-Length: 3',
|
||||||
'',
|
'',
|
||||||
'a=a'))
|
'a=a'))
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write(request)
|
fd.write(request)
|
||||||
|
|
||||||
# send some junk after the actual request
|
# send some junk after the actual request
|
||||||
fd.write('01234567890123456789')
|
fd.write('01234567890123456789')
|
||||||
reqline, headers, body = read_http(sock)
|
reqline, headers, body = read_http(sock)
|
||||||
self.assertEqual(body, 'a is a, body is a=a')
|
self.assertEqual(body, 'a is a, body is a=a')
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def test_008_correctresponse(self):
|
def test_008_correctresponse(self):
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||||
response_line_200,_,_ = read_http(sock)
|
response_line_200,_,_ = read_http(sock)
|
||||||
@@ -233,7 +233,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
self.site.application = chunked_app
|
self.site.application = chunked_app
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
self.assert_('Transfer-Encoding: chunked' in fd.read())
|
self.assert_('Transfer-Encoding: chunked' in fd.read())
|
||||||
@@ -242,7 +242,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
self.site.application = chunked_app
|
self.site.application = chunked_app
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
self.assert_('Transfer-Encoding: chunked' not in fd.read())
|
self.assert_('Transfer-Encoding: chunked' not in fd.read())
|
||||||
@@ -251,7 +251,7 @@ class TestHttpd(tests.TestCase):
|
|||||||
self.site.application = big_chunks
|
self.site.application = big_chunks
|
||||||
sock = api.connect_tcp(
|
sock = api.connect_tcp(
|
||||||
('127.0.0.1', 12346))
|
('127.0.0.1', 12346))
|
||||||
|
|
||||||
fd = sock.makeGreenFile()
|
fd = sock.makeGreenFile()
|
||||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||||
headers = fd.readuntil('\r\n\r\n')
|
headers = fd.readuntil('\r\n\r\n')
|
||||||
@@ -274,16 +274,30 @@ class TestHttpd(tests.TestCase):
|
|||||||
|
|
||||||
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
||||||
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
||||||
|
|
||||||
sock = api.ssl_listener(('', 4201), certificate_file, private_key_file)
|
sock = api.ssl_listener(('', 4201), certificate_file, private_key_file)
|
||||||
|
|
||||||
api.spawn(wsgi.server, sock, wsgi_app)
|
api.spawn(wsgi.server, sock, wsgi_app)
|
||||||
|
|
||||||
print "pre request"
|
print "pre request"
|
||||||
result = httpc.post("https://localhost:4201/foo", "abc")
|
result = httpc.post("https://localhost:4201/foo", "abc")
|
||||||
self.assertEquals(result, 'abc')
|
self.assertEquals(result, 'abc')
|
||||||
print "post request"
|
print "post request"
|
||||||
|
|
||||||
|
def test_013_empty_return(self):
|
||||||
|
from eventlet import httpc
|
||||||
|
def wsgi_app(environ, start_response):
|
||||||
|
start_response("200 OK", [])
|
||||||
|
return [""]
|
||||||
|
|
||||||
|
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
||||||
|
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
||||||
|
sock = api.ssl_listener(('', 4202), certificate_file, private_key_file)
|
||||||
|
api.spawn(wsgi.server, sock, wsgi_app)
|
||||||
|
|
||||||
|
res = httpc.get("https://localhost:4202/foo")
|
||||||
|
self.assertEquals(res, '')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
tests.main()
|
tests.main()
|
||||||
|
Reference in New Issue
Block a user