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
|
||||
|
||||
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):
|
||||
try:
|
||||
|
@@ -1,5 +1,5 @@
|
||||
"""\
|
||||
@file httpd_test.py
|
||||
@file wsgi_test.py
|
||||
@author Donovan Preston
|
||||
|
||||
Copyright (c) 2007, Linden Research, Inc.
|
||||
@@ -43,7 +43,7 @@ def hello_world(env, start_response):
|
||||
if env['PATH_INFO'] == 'notexist':
|
||||
start_response('404 Not Found', [('Content-type', 'text/plain')])
|
||||
return ["not found"]
|
||||
|
||||
|
||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||
return ["hello world"]
|
||||
|
||||
@@ -123,7 +123,7 @@ class TestHttpd(tests.TestCase):
|
||||
def test_001_server(self):
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = fd.read()
|
||||
@@ -135,7 +135,7 @@ class TestHttpd(tests.TestCase):
|
||||
def test_002_keepalive(self):
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
read_http(sock)
|
||||
@@ -147,7 +147,7 @@ class TestHttpd(tests.TestCase):
|
||||
# This should go in greenio_test
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
cancel = api.exc_after(1, RuntimeError)
|
||||
@@ -189,7 +189,7 @@ class TestHttpd(tests.TestCase):
|
||||
status = result.split(' ')[1]
|
||||
self.assertEqual(status, '414')
|
||||
fd.close()
|
||||
|
||||
|
||||
def test_007_get_arg(self):
|
||||
# define a new handler that does a get_arg as well as a read_body
|
||||
def new_app(env, start_response):
|
||||
@@ -201,24 +201,24 @@ class TestHttpd(tests.TestCase):
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
request = '\r\n'.join((
|
||||
'POST / HTTP/1.0',
|
||||
'Host: localhost',
|
||||
'Content-Length: 3',
|
||||
'POST / HTTP/1.0',
|
||||
'Host: localhost',
|
||||
'Content-Length: 3',
|
||||
'',
|
||||
'a=a'))
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write(request)
|
||||
|
||||
|
||||
# send some junk after the actual request
|
||||
fd.write('01234567890123456789')
|
||||
reqline, headers, body = read_http(sock)
|
||||
self.assertEqual(body, 'a is a, body is a=a')
|
||||
fd.close()
|
||||
|
||||
|
||||
def test_008_correctresponse(self):
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
response_line_200,_,_ = read_http(sock)
|
||||
@@ -233,7 +233,7 @@ class TestHttpd(tests.TestCase):
|
||||
self.site.application = chunked_app
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
self.assert_('Transfer-Encoding: chunked' in fd.read())
|
||||
@@ -242,7 +242,7 @@ class TestHttpd(tests.TestCase):
|
||||
self.site.application = chunked_app
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
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())
|
||||
@@ -251,7 +251,7 @@ class TestHttpd(tests.TestCase):
|
||||
self.site.application = big_chunks
|
||||
sock = api.connect_tcp(
|
||||
('127.0.0.1', 12346))
|
||||
|
||||
|
||||
fd = sock.makeGreenFile()
|
||||
fd.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\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')
|
||||
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
||||
|
||||
|
||||
sock = api.ssl_listener(('', 4201), certificate_file, private_key_file)
|
||||
|
||||
|
||||
api.spawn(wsgi.server, sock, wsgi_app)
|
||||
|
||||
|
||||
print "pre request"
|
||||
result = httpc.post("https://localhost:4201/foo", "abc")
|
||||
self.assertEquals(result, 'abc')
|
||||
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__':
|
||||
tests.main()
|
||||
|
Reference in New Issue
Block a user