little clean up
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import errno
|
||||
import os
|
||||
from socket import socket as _original_socket
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import warnings
|
||||
|
||||
from eventlet.support import get_errno, six
|
||||
import eventlet
|
||||
from eventlet.hubs import trampoline, notify_opened, IOClosed
|
||||
from eventlet.support import get_errno, six
|
||||
|
||||
__all__ = [
|
||||
'GreenSocket', '_GLOBAL_DEFAULT_TIMEOUT', 'set_nonblocking',
|
||||
@@ -24,6 +24,8 @@ if sys.platform[:3] == "win":
|
||||
if six.PY2:
|
||||
_python2_fileobject = socket._fileobject
|
||||
|
||||
_original_socket = eventlet.patcher.original('socket').socket
|
||||
|
||||
|
||||
def socket_connect(descriptor, address):
|
||||
"""
|
||||
|
@@ -256,6 +256,16 @@ def setup():
|
||||
else:
|
||||
_setup_already = True
|
||||
|
||||
assert _nthreads >= 0, "Can't specify negative number of threads"
|
||||
if _nthreads == 0:
|
||||
import warnings
|
||||
warnings.warn("Zero threads in tpool. All tpool.execute calls will\
|
||||
execute in main thread. Check the value of the environment \
|
||||
variable EVENTLET_THREADPOOL_SIZE.", RuntimeWarning)
|
||||
_reqq = Queue(maxsize=-1)
|
||||
_rspq = Queue(maxsize=-1)
|
||||
|
||||
# connected socket pair
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind(('127.0.0.1', 0))
|
||||
sock.listen(1)
|
||||
@@ -265,14 +275,6 @@ def setup():
|
||||
sock.close()
|
||||
_rsock = greenio.GreenSocket(csock)
|
||||
|
||||
_reqq = Queue(maxsize=-1)
|
||||
_rspq = Queue(maxsize=-1)
|
||||
assert _nthreads >= 0, "Can't specify negative number of threads"
|
||||
if _nthreads == 0:
|
||||
import warnings
|
||||
warnings.warn("Zero threads in tpool. All tpool.execute calls will\
|
||||
execute in main thread. Check the value of the environment \
|
||||
variable EVENTLET_THREADPOOL_SIZE.", RuntimeWarning)
|
||||
for i in six.moves.range(_nthreads):
|
||||
t = threading.Thread(target=tworker,
|
||||
name="tpool_thread_%s" % i)
|
||||
|
@@ -7,13 +7,12 @@ import traceback
|
||||
import types
|
||||
import warnings
|
||||
|
||||
from eventlet.green import BaseHTTPServer
|
||||
from eventlet.green import socket
|
||||
from eventlet import greenio
|
||||
from eventlet import greenpool
|
||||
from eventlet import support
|
||||
from eventlet.support import safe_writelines, six, writeall
|
||||
|
||||
from eventlet.green import BaseHTTPServer
|
||||
from eventlet.green import socket
|
||||
from eventlet.support.six.moves import urllib
|
||||
|
||||
|
||||
|
@@ -299,17 +299,22 @@ def get_database_auth():
|
||||
return retval
|
||||
|
||||
|
||||
def run_python(path, env=None):
|
||||
if not path.endswith('.py'):
|
||||
path += '.py'
|
||||
path = os.path.abspath(path)
|
||||
src_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
def run_python(path, env=None, args=None):
|
||||
new_argv = [sys.executable]
|
||||
new_env = os.environ.copy()
|
||||
new_env['PYTHONPATH'] = os.pathsep.join(sys.path + [src_dir])
|
||||
if path:
|
||||
if not path.endswith('.py'):
|
||||
path += '.py'
|
||||
path = os.path.abspath(path)
|
||||
new_argv.append(path)
|
||||
src_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
new_env['PYTHONPATH'] = os.pathsep.join(sys.path + [src_dir])
|
||||
if env:
|
||||
new_env.update(env)
|
||||
if args:
|
||||
new_argv.extend(args)
|
||||
p = subprocess.Popen(
|
||||
[sys.executable, path],
|
||||
new_argv,
|
||||
env=new_env,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdin=subprocess.PIPE,
|
||||
@@ -319,8 +324,8 @@ def run_python(path, env=None):
|
||||
return output
|
||||
|
||||
|
||||
def run_isolated(path, prefix='tests/isolated/', env=None):
|
||||
output = run_python(prefix + path, env=env).rstrip()
|
||||
def run_isolated(path, prefix='tests/isolated/', env=None, args=None):
|
||||
output = run_python(prefix + path, env=env, args=args).rstrip()
|
||||
if output.startswith(b'skip'):
|
||||
parts = output.split(b':', 1)
|
||||
skip_args = []
|
||||
|
@@ -1,114 +1,46 @@
|
||||
import os
|
||||
from eventlet.support import six
|
||||
from tests.patcher_test import ProcessBase
|
||||
from tests import skip_with_pyevent
|
||||
import tests
|
||||
|
||||
|
||||
class Socket(ProcessBase):
|
||||
def test_patched_thread(self):
|
||||
new_mod = """from eventlet.green import socket
|
||||
def test_hub_selects():
|
||||
code = 'from eventlet import hubs\nprint(hubs.get_hub())'
|
||||
output = tests.run_python(
|
||||
path=None,
|
||||
env={'EVENTLET_HUB': 'selects'},
|
||||
args=['-c', code],
|
||||
)
|
||||
assert output.count(b'\n') == 1
|
||||
assert b'eventlet.hubs.selects.Hub' in output
|
||||
|
||||
|
||||
def test_tpool_dns():
|
||||
code = '''\
|
||||
from eventlet.green import socket
|
||||
socket.gethostbyname('localhost')
|
||||
socket.getaddrinfo('localhost', 80)
|
||||
"""
|
||||
os.environ['EVENTLET_TPOOL_DNS'] = 'yes'
|
||||
try:
|
||||
self.write_to_tempfile("newmod", new_mod)
|
||||
output, lines = self.launch_subprocess('newmod.py')
|
||||
self.assertEqual(len(lines), 1, lines)
|
||||
finally:
|
||||
del os.environ['EVENTLET_TPOOL_DNS']
|
||||
print('pass')
|
||||
'''
|
||||
output = tests.run_python(
|
||||
path=None,
|
||||
env={'EVENTLET_TPOOL_DNS': 'yes'},
|
||||
args=['-c', code],
|
||||
)
|
||||
assert output.rstrip() == b'pass'
|
||||
|
||||
|
||||
class Tpool(ProcessBase):
|
||||
@skip_with_pyevent
|
||||
def test_tpool_size(self):
|
||||
expected = "40"
|
||||
normal = "20"
|
||||
new_mod = """from eventlet import tpool
|
||||
import eventlet
|
||||
import time
|
||||
current = [0]
|
||||
highwater = [0]
|
||||
def count():
|
||||
current[0] += 1
|
||||
time.sleep(0.1)
|
||||
if current[0] > highwater[0]:
|
||||
highwater[0] = current[0]
|
||||
current[0] -= 1
|
||||
expected = %s
|
||||
normal = %s
|
||||
p = eventlet.GreenPool()
|
||||
for i in range(expected*2):
|
||||
p.spawn(tpool.execute, count)
|
||||
p.waitall()
|
||||
assert highwater[0] > 20, "Highwater %%s <= %%s" %% (highwater[0], normal)
|
||||
"""
|
||||
os.environ['EVENTLET_THREADPOOL_SIZE'] = expected
|
||||
try:
|
||||
self.write_to_tempfile("newmod", new_mod % (expected, normal))
|
||||
output, lines = self.launch_subprocess('newmod.py')
|
||||
self.assertEqual(len(lines), 1, lines)
|
||||
finally:
|
||||
del os.environ['EVENTLET_THREADPOOL_SIZE']
|
||||
|
||||
def test_tpool_negative(self):
|
||||
new_mod = """from eventlet import tpool
|
||||
import eventlet
|
||||
import time
|
||||
def do():
|
||||
print("should not get here")
|
||||
try:
|
||||
tpool.execute(do)
|
||||
except AssertionError:
|
||||
print("success")
|
||||
"""
|
||||
os.environ['EVENTLET_THREADPOOL_SIZE'] = "-1"
|
||||
try:
|
||||
self.write_to_tempfile("newmod", new_mod)
|
||||
output, lines = self.launch_subprocess('newmod.py')
|
||||
self.assertEqual(len(lines), 2, lines)
|
||||
self.assertEqual(lines[0], "success", output)
|
||||
finally:
|
||||
del os.environ['EVENTLET_THREADPOOL_SIZE']
|
||||
|
||||
def test_tpool_zero(self):
|
||||
new_mod = """from eventlet import tpool
|
||||
import eventlet
|
||||
import time
|
||||
def do():
|
||||
print("ran it")
|
||||
tpool.execute(do)
|
||||
"""
|
||||
os.environ['EVENTLET_THREADPOOL_SIZE'] = "0"
|
||||
try:
|
||||
self.write_to_tempfile("newmod", new_mod)
|
||||
output, lines = self.launch_subprocess('newmod.py')
|
||||
self.assertEqual(len(lines), 4, lines)
|
||||
self.assertEqual(lines[-2], 'ran it', lines)
|
||||
assert 'Warning' in lines[1] or 'Warning' in lines[0], lines
|
||||
finally:
|
||||
del os.environ['EVENTLET_THREADPOOL_SIZE']
|
||||
@tests.skip_with_pyevent
|
||||
def test_tpool_size():
|
||||
expected = '40'
|
||||
normal = '20'
|
||||
tests.run_isolated(
|
||||
path='env_tpool_size.py',
|
||||
env={'EVENTLET_THREADPOOL_SIZE': expected},
|
||||
args=[expected, normal],
|
||||
)
|
||||
|
||||
|
||||
class Hub(ProcessBase):
|
||||
def test_tpool_negative():
|
||||
tests.run_isolated('env_tpool_negative.py', env={'EVENTLET_THREADPOOL_SIZE': '-1'})
|
||||
|
||||
def setUp(self):
|
||||
super(Hub, self).setUp()
|
||||
self.old_environ = os.environ.get('EVENTLET_HUB')
|
||||
os.environ['EVENTLET_HUB'] = 'selects'
|
||||
|
||||
def tearDown(self):
|
||||
if self.old_environ:
|
||||
os.environ['EVENTLET_HUB'] = self.old_environ
|
||||
else:
|
||||
del os.environ['EVENTLET_HUB']
|
||||
super(Hub, self).tearDown()
|
||||
|
||||
def test_eventlet_hub(self):
|
||||
new_mod = """from eventlet import hubs
|
||||
print(hubs.get_hub())
|
||||
"""
|
||||
self.write_to_tempfile("newmod", new_mod)
|
||||
output, lines = self.launch_subprocess('newmod.py')
|
||||
self.assertEqual(len(lines), 2, "\n".join(lines))
|
||||
assert "selects" in lines[0]
|
||||
def test_tpool_zero():
|
||||
tests.run_isolated('env_tpool_zero.py', env={'EVENTLET_THREADPOOL_SIZE': '0'})
|
||||
|
@@ -12,6 +12,7 @@ import tempfile
|
||||
|
||||
from nose.tools import eq_
|
||||
|
||||
import eventlet
|
||||
from eventlet import event, greenio, debug
|
||||
from eventlet.hubs import get_hub
|
||||
from eventlet.green import select, socket, time, ssl
|
||||
@@ -877,3 +878,41 @@ def test_socket_del_fails_gracefully_when_not_fully_initialized():
|
||||
|
||||
def test_double_close_219():
|
||||
tests.run_isolated('greenio_double_close_219.py')
|
||||
|
||||
|
||||
def test_socket_file_read_non_int():
|
||||
listen_socket = eventlet.listen(('localhost', 0))
|
||||
|
||||
def server():
|
||||
conn, _ = listen_socket.accept()
|
||||
conn.recv(1)
|
||||
conn.sendall('response')
|
||||
conn.close()
|
||||
|
||||
eventlet.spawn(server)
|
||||
sock = eventlet.connect(listen_socket.getsockname())
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'?')
|
||||
fd.flush()
|
||||
with eventlet.Timeout(1):
|
||||
try:
|
||||
fd.read("This shouldn't work")
|
||||
assert False
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
def test_pipe_context():
|
||||
# ensure using a pipe as a context actually closes it.
|
||||
r, w = os.pipe()
|
||||
r = greenio.GreenPipe(r)
|
||||
w = greenio.GreenPipe(w, 'w')
|
||||
|
||||
with r:
|
||||
pass
|
||||
assert r.closed and not w.closed
|
||||
|
||||
with w as f:
|
||||
assert f == w
|
||||
assert r.closed and w.closed
|
||||
|
@@ -1,25 +0,0 @@
|
||||
from __future__ import with_statement
|
||||
|
||||
import os
|
||||
|
||||
from eventlet import greenio
|
||||
from tests import LimitedTestCase
|
||||
|
||||
|
||||
class TestGreenPipeWithStatement(LimitedTestCase):
|
||||
def test_pipe_context(self):
|
||||
# ensure using a pipe as a context actually closes it.
|
||||
r, w = os.pipe()
|
||||
|
||||
r = greenio.GreenPipe(r)
|
||||
w = greenio.GreenPipe(w, 'w')
|
||||
|
||||
with r:
|
||||
pass
|
||||
|
||||
assert r.closed and not w.closed
|
||||
|
||||
with w as f:
|
||||
assert f == w
|
||||
|
||||
assert r.closed and w.closed
|
11
tests/isolated/env_tpool_negative.py
Normal file
11
tests/isolated/env_tpool_negative.py
Normal file
@@ -0,0 +1,11 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
from eventlet import tpool
|
||||
|
||||
def do():
|
||||
print("should not get here")
|
||||
try:
|
||||
tpool.execute(do)
|
||||
except AssertionError:
|
||||
print('pass')
|
26
tests/isolated/env_tpool_size.py
Normal file
26
tests/isolated/env_tpool_size.py
Normal file
@@ -0,0 +1,26 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import time
|
||||
from eventlet import tpool
|
||||
import eventlet
|
||||
|
||||
current = [0]
|
||||
highwater = [0]
|
||||
|
||||
def count():
|
||||
current[0] += 1
|
||||
time.sleep(0.01)
|
||||
if current[0] > highwater[0]:
|
||||
highwater[0] = current[0]
|
||||
current[0] -= 1
|
||||
|
||||
expected = int(sys.argv[1])
|
||||
normal = int(sys.argv[2])
|
||||
p = eventlet.GreenPool()
|
||||
for i in range(expected * 2):
|
||||
p.spawn(tpool.execute, count)
|
||||
p.waitall()
|
||||
assert highwater[0] > normal, "Highwater %s <= %s" % (highwater[0], normal)
|
||||
print('pass')
|
22
tests/isolated/env_tpool_zero.py
Normal file
22
tests/isolated/env_tpool_zero.py
Normal file
@@ -0,0 +1,22 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import warnings
|
||||
from eventlet import tpool
|
||||
g = [False]
|
||||
|
||||
def do():
|
||||
g[0] = True
|
||||
|
||||
with warnings.catch_warnings(record=True) as ws:
|
||||
warnings.simplefilter('always')
|
||||
|
||||
tpool.execute(do)
|
||||
|
||||
assert len(ws) == 1
|
||||
msg = str(ws[0].message)
|
||||
assert 'Zero threads in tpool' in msg
|
||||
assert 'EVENTLET_THREADPOOL_SIZE' in msg
|
||||
|
||||
assert g[0]
|
||||
print('pass')
|
@@ -1,16 +1,13 @@
|
||||
__test__ = False
|
||||
|
||||
|
||||
def main():
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import eventlet
|
||||
try:
|
||||
from dns import reversename
|
||||
except ImportError:
|
||||
print('skip:require dns (package dnspython)')
|
||||
return
|
||||
sys.exit(1)
|
||||
eventlet.monkey_patch(all=True)
|
||||
reversename.from_address('127.0.0.1')
|
||||
print('pass')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@@ -1,7 +1,6 @@
|
||||
__test__ = False
|
||||
|
||||
|
||||
def main():
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
import subprocess
|
||||
@@ -17,6 +16,3 @@ def main():
|
||||
|
||||
f.close() # OSError, because the fd 3 has already been closed
|
||||
print('pass')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@@ -1,6 +1,3 @@
|
||||
from __future__ import print_function
|
||||
|
||||
# no standard tests in this file, ignore
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@@ -1,3 +1,5 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
@@ -1,11 +1,3 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
import eventlet
|
||||
|
||||
|
||||
# no standard tests in this file, ignore
|
||||
__test__ = False
|
||||
|
||||
|
||||
@@ -14,6 +6,9 @@ def do_import():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import eventlet
|
||||
|
||||
eventlet.monkey_patch()
|
||||
threading = eventlet.patcher.original('threading')
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
@@ -1,11 +1,8 @@
|
||||
# Issue #185: test threading.Condition with monkey-patching
|
||||
import eventlet
|
||||
|
||||
# no standard tests in this file, ignore
|
||||
__test__ = False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
||||
import threading
|
||||
|
@@ -1,11 +1,8 @@
|
||||
# Issue #223: test threading.Thread.join with monkey-patching
|
||||
import eventlet
|
||||
|
||||
# no standard tests in this file, ignore
|
||||
__test__ = False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
||||
import threading
|
||||
|
@@ -1,7 +1,5 @@
|
||||
# no standard tests in this file, ignore
|
||||
__test__ = False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import eventlet
|
||||
|
@@ -291,18 +291,20 @@ import time
|
||||
self.assertEqual(len(lines), 2, "\n".join(lines))
|
||||
|
||||
|
||||
class Subprocess(ProcessBase):
|
||||
def test_monkeypatched_subprocess(self):
|
||||
new_mod = """import eventlet
|
||||
def test_subprocess_after_monkey_patch():
|
||||
code = '''\
|
||||
import sys
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
from eventlet.green import subprocess
|
||||
|
||||
subprocess.Popen(['true'], stdin=subprocess.PIPE)
|
||||
print("done")
|
||||
"""
|
||||
self.write_to_tempfile("newmod", new_mod)
|
||||
output, lines = self.launch_subprocess('newmod')
|
||||
self.assertEqual(output, "done\n", output)
|
||||
subprocess.Popen([sys.executable, '-c', ''], stdin=subprocess.PIPE).wait()
|
||||
print('pass')
|
||||
'''
|
||||
output = tests.run_python(
|
||||
path=None,
|
||||
args=['-c', code],
|
||||
)
|
||||
assert output.rstrip() == b'pass'
|
||||
|
||||
|
||||
class Threading(ProcessBase):
|
||||
@@ -324,8 +326,8 @@ print(len(_threading._active))
|
||||
output, lines = self.launch_subprocess('newmod')
|
||||
self.assertEqual(len(lines), 4, "\n".join(lines))
|
||||
assert lines[0].startswith('<Thread'), lines[0]
|
||||
self.assertEqual(lines[1], "1", lines[1])
|
||||
self.assertEqual(lines[2], "1", lines[2])
|
||||
assert lines[1] == '1', lines
|
||||
assert lines[2] == '1', lines
|
||||
|
||||
def test_threading(self):
|
||||
new_mod = """import eventlet
|
||||
|
@@ -65,4 +65,4 @@ def test_semaphore_contention():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
@@ -8,7 +8,7 @@ from eventlet.green import httplib
|
||||
from eventlet.green import socket
|
||||
from eventlet.support import six
|
||||
|
||||
from tests.wsgi_test import _TestBase
|
||||
import tests.wsgi_test
|
||||
|
||||
|
||||
# demo app
|
||||
@@ -32,7 +32,7 @@ def handle(ws):
|
||||
wsapp = websocket.WebSocketWSGI(handle)
|
||||
|
||||
|
||||
class TestWebSocket(_TestBase):
|
||||
class TestWebSocket(tests.wsgi_test._TestBase):
|
||||
TEST_TIMEOUT = 5
|
||||
|
||||
def set_site(self):
|
||||
@@ -42,11 +42,11 @@ class TestWebSocket(_TestBase):
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Upgrade: websocket",
|
||||
# NOTE: intentionally no connection header
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -58,11 +58,11 @@ class TestWebSocket(_TestBase):
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Upgrade: websocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -73,11 +73,11 @@ class TestWebSocket(_TestBase):
|
||||
# No Upgrade now
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -91,12 +91,12 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: websocket",
|
||||
"Connection: %s" % http_connection,
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
"Sec-WebSocket-Key: d9MXuOzlVQ0h+qRllvSCIg==",
|
||||
]
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
result = sock.recv(1024)
|
||||
@@ -114,14 +114,12 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: websocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
"Sec-WebSocket-Key: d9MXuOzlVQ0h+qRllvSCIg==",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024)
|
||||
ws = websocket.RFC6455WebSocket(sock, {}, client=True)
|
||||
@@ -154,13 +152,12 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: websocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
"Sec-WebSocket-Key: d9MXuOzlVQ0h+qRllvSCIg==",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.close() # close while the app is running
|
||||
@@ -187,13 +184,12 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: websocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
"Sec-WebSocket-Key: d9MXuOzlVQ0h+qRllvSCIg==",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024) # get the headers
|
||||
closeframe = struct.pack('!BBIH', 1 << 7 | 8, 1 << 7 | 2, 0, 1000)
|
||||
@@ -221,13 +217,12 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: websocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Version: 13",
|
||||
"Sec-WebSocket-Key: d9MXuOzlVQ0h+qRllvSCIg==",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.sendall(b'\x07\xff') # Weird packet.
|
||||
|
@@ -8,9 +8,9 @@ from eventlet.green import httplib
|
||||
from eventlet.support import six
|
||||
from eventlet.websocket import WebSocket, WebSocketWSGI
|
||||
|
||||
from tests import certificate_file, LimitedTestCase, mock, private_key_file
|
||||
from tests import skip_if_no_ssl
|
||||
from tests.wsgi_test import _TestBase
|
||||
import tests
|
||||
from tests import mock
|
||||
import tests.wsgi_test
|
||||
|
||||
|
||||
# demo app
|
||||
@@ -34,14 +34,14 @@ def handle(ws):
|
||||
wsapp = WebSocketWSGI(handle)
|
||||
|
||||
|
||||
class TestWebSocket(_TestBase):
|
||||
class TestWebSocket(tests.wsgi_test._TestBase):
|
||||
TEST_TIMEOUT = 5
|
||||
|
||||
def set_site(self):
|
||||
self.site = wsapp
|
||||
|
||||
def test_incorrect_headers(self):
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo")
|
||||
response = http.getresponse()
|
||||
assert response.status == 400
|
||||
@@ -50,11 +50,11 @@ class TestWebSocket(_TestBase):
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Upgrade: WebSocket",
|
||||
# NOTE: intentionally no connection header
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -67,11 +67,11 @@ class TestWebSocket(_TestBase):
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Upgrade: WebSocket",
|
||||
# NOTE: intentionally no connection header
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -83,13 +83,13 @@ class TestWebSocket(_TestBase):
|
||||
headers = dict(kv.split(': ') for kv in [
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
# NOTE: Intentionally no Key2 header
|
||||
])
|
||||
http = httplib.HTTPConnection('localhost', self.port)
|
||||
http = httplib.HTTPConnection(*self.server_addr)
|
||||
http.request("GET", "/echo", headers=headers)
|
||||
resp = http.getresponse()
|
||||
|
||||
@@ -102,12 +102,11 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
result = sock.recv(1024)
|
||||
@@ -116,8 +115,8 @@ class TestWebSocket(_TestBase):
|
||||
'HTTP/1.1 101 Web Socket Protocol Handshake',
|
||||
'Upgrade: WebSocket',
|
||||
'Connection: Upgrade',
|
||||
'WebSocket-Origin: http://localhost:%s' % self.port,
|
||||
'WebSocket-Location: ws://localhost:%s/echo\r\n\r\n' % self.port,
|
||||
'WebSocket-Origin: http://%s:%s' % self.server_addr,
|
||||
'WebSocket-Location: ws://%s:%s/echo\r\n\r\n' % self.server_addr,
|
||||
])))
|
||||
|
||||
def test_correct_upgrade_request_76(self):
|
||||
@@ -125,14 +124,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
result = sock.recv(1024)
|
||||
@@ -141,9 +139,9 @@ class TestWebSocket(_TestBase):
|
||||
'HTTP/1.1 101 WebSocket Protocol Handshake',
|
||||
'Upgrade: WebSocket',
|
||||
'Connection: Upgrade',
|
||||
'Sec-WebSocket-Origin: http://localhost:%s' % self.port,
|
||||
'Sec-WebSocket-Origin: http://%s:%s' % self.server_addr,
|
||||
'Sec-WebSocket-Protocol: ws',
|
||||
'Sec-WebSocket-Location: ws://localhost:%s/echo\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.port,
|
||||
'Sec-WebSocket-Location: ws://%s:%s/echo\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.server_addr,
|
||||
])))
|
||||
|
||||
def test_query_string(self):
|
||||
@@ -152,14 +150,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo?query_string HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
result = sock.recv(1024)
|
||||
@@ -167,10 +164,10 @@ class TestWebSocket(_TestBase):
|
||||
'HTTP/1.1 101 WebSocket Protocol Handshake',
|
||||
'Upgrade: WebSocket',
|
||||
'Connection: Upgrade',
|
||||
'Sec-WebSocket-Origin: http://localhost:%s' % self.port,
|
||||
'Sec-WebSocket-Origin: http://%s:%s' % self.server_addr,
|
||||
'Sec-WebSocket-Protocol: ws',
|
||||
'Sec-WebSocket-Location: '
|
||||
'ws://localhost:%s/echo?query_string\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.port,
|
||||
'ws://%s:%s/echo?query_string\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.server_addr,
|
||||
])))
|
||||
|
||||
def test_empty_query_string(self):
|
||||
@@ -179,14 +176,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo? HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
result = sock.recv(1024)
|
||||
@@ -194,9 +190,9 @@ class TestWebSocket(_TestBase):
|
||||
'HTTP/1.1 101 WebSocket Protocol Handshake',
|
||||
'Upgrade: WebSocket',
|
||||
'Connection: Upgrade',
|
||||
'Sec-WebSocket-Origin: http://localhost:%s' % self.port,
|
||||
'Sec-WebSocket-Origin: http://%s:%s' % self.server_addr,
|
||||
'Sec-WebSocket-Protocol: ws',
|
||||
'Sec-WebSocket-Location: ws://localhost:%s/echo?\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.port,
|
||||
'Sec-WebSocket-Location: ws://%s:%s/echo?\r\n\r\n8jKS\'y:G*Co,Wxa-' % self.server_addr,
|
||||
])))
|
||||
|
||||
def test_sending_messages_to_websocket_75(self):
|
||||
@@ -204,12 +200,11 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024)
|
||||
@@ -230,14 +225,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
sock.recv(1024)
|
||||
@@ -258,12 +252,11 @@ class TestWebSocket(_TestBase):
|
||||
"GET /range HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
resp = sock.recv(1024)
|
||||
@@ -281,14 +274,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /range HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
resp = sock.recv(1024)
|
||||
@@ -321,12 +313,11 @@ class TestWebSocket(_TestBase):
|
||||
"GET /range HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.close() # close while the app is running
|
||||
@@ -353,14 +344,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /range HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.close() # close while the app is running
|
||||
@@ -387,14 +377,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.sendall(b'\xff\x00') # "Close the connection" packet.
|
||||
@@ -421,14 +410,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
sock.recv(1024) # get the headers
|
||||
sock.sendall(b'\xef\x00') # Weird packet.
|
||||
@@ -440,15 +428,13 @@ class TestWebSocket(_TestBase):
|
||||
"GET / HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
resp = sock.recv(1024)
|
||||
headers, result = resp.split(b'\r\n\r\n')
|
||||
@@ -475,12 +461,11 @@ class TestWebSocket(_TestBase):
|
||||
"GET /error HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"WebSocket-Protocol: ws",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n'))
|
||||
sock.recv(1024)
|
||||
done_with_request.wait()
|
||||
@@ -506,43 +491,41 @@ class TestWebSocket(_TestBase):
|
||||
"GET /error HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
sock.recv(1024)
|
||||
done_with_request.wait()
|
||||
assert error_detected[0]
|
||||
|
||||
|
||||
class TestWebSocketSSL(_TestBase):
|
||||
class TestWebSocketSSL(tests.wsgi_test._TestBase):
|
||||
def set_site(self):
|
||||
self.site = wsapp
|
||||
|
||||
@skip_if_no_ssl
|
||||
@tests.skip_if_no_ssl
|
||||
def test_ssl_sending_messages(self):
|
||||
s = eventlet.wrap_ssl(eventlet.listen(('localhost', 0)),
|
||||
certfile=certificate_file,
|
||||
keyfile=private_key_file,
|
||||
certfile=tests.certificate_file,
|
||||
keyfile=tests.private_key_file,
|
||||
server_side=True)
|
||||
self.spawn_server(sock=s)
|
||||
connect = [
|
||||
"GET /echo HTTP/1.1",
|
||||
"Upgrade: WebSocket",
|
||||
"Connection: Upgrade",
|
||||
"Host: localhost:%s" % self.port,
|
||||
"Origin: http://localhost:%s" % self.port,
|
||||
"Host: %s:%s" % self.server_addr,
|
||||
"Origin: http://%s:%s" % self.server_addr,
|
||||
"Sec-WebSocket-Protocol: ws",
|
||||
"Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5",
|
||||
"Sec-WebSocket-Key2: 12998 5 Y3 1 .P00",
|
||||
]
|
||||
sock = eventlet.wrap_ssl(eventlet.connect(
|
||||
('localhost', self.port)))
|
||||
sock = eventlet.wrap_ssl(eventlet.connect(self.server_addr))
|
||||
|
||||
sock.sendall(six.b('\r\n'.join(connect) + '\r\n\r\n^n:ds[4U'))
|
||||
first_resp = b''
|
||||
@@ -553,8 +536,9 @@ class TestWebSocketSSL(_TestBase):
|
||||
# make sure it sets the wss: protocol on the location header
|
||||
loc_line = [x for x in first_resp.split(b"\r\n")
|
||||
if x.lower().startswith(b'sec-websocket-location')][0]
|
||||
self.assert_(b"wss://localhost" in loc_line,
|
||||
"Expecting wss protocol in location: %s" % loc_line)
|
||||
expect_wss = ('wss://%s:%s' % self.server_addr).encode()
|
||||
assert expect_wss in loc_line, "Expecting wss protocol in location: %s" % loc_line
|
||||
|
||||
sock.sendall(b'\x00hello\xFF')
|
||||
result = sock.recv(1024)
|
||||
self.assertEqual(result, b'\x00hello\xff')
|
||||
@@ -568,7 +552,7 @@ class TestWebSocketSSL(_TestBase):
|
||||
eventlet.sleep(0.01)
|
||||
|
||||
|
||||
class TestWebSocketObject(LimitedTestCase):
|
||||
class TestWebSocketObject(tests.LimitedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mock_socket = s = mock.Mock()
|
||||
|
@@ -10,20 +10,17 @@ import tempfile
|
||||
import traceback
|
||||
import unittest
|
||||
|
||||
from nose.tools import eq_
|
||||
|
||||
import eventlet
|
||||
from eventlet import debug
|
||||
from eventlet import event
|
||||
from eventlet.green import socket as greensocket
|
||||
from eventlet.green import ssl
|
||||
from eventlet import greenio
|
||||
from eventlet import greenthread
|
||||
from eventlet import support
|
||||
from eventlet.support import bytes_to_str, capture_stderr, six
|
||||
from eventlet import tpool
|
||||
from eventlet import wsgi
|
||||
|
||||
from eventlet.green import socket as greensocket
|
||||
from eventlet.green import ssl
|
||||
from eventlet.support import bytes_to_str, capture_stderr, six
|
||||
import tests
|
||||
|
||||
|
||||
@@ -139,24 +136,13 @@ class IterableSite(Site):
|
||||
CONTENT_LENGTH = 'content-length'
|
||||
|
||||
|
||||
"""
|
||||
HTTP/1.1 200 OK
|
||||
Date: foo
|
||||
Content-length: 11
|
||||
|
||||
hello world
|
||||
"""
|
||||
|
||||
|
||||
def recvall(socket_):
|
||||
def recvall(sock):
|
||||
result = b''
|
||||
while True:
|
||||
chunk = socket_.recv()
|
||||
result += chunk
|
||||
chunk = sock.recv(16 << 10)
|
||||
if chunk == b'':
|
||||
break
|
||||
|
||||
return result
|
||||
return result
|
||||
result += chunk
|
||||
|
||||
|
||||
class ConnectionClosed(Exception):
|
||||
@@ -247,7 +233,7 @@ class _TestBase(tests.LimitedTestCase):
|
||||
"""Spawns a new wsgi server with the given arguments using
|
||||
:meth:`spawn_thread`.
|
||||
|
||||
Sets self.port to the port of the server
|
||||
Sets `self.server_addr` to (host, port) tuple suitable for `socket.connect`.
|
||||
"""
|
||||
new_kwargs = dict(max_size=128,
|
||||
log=self.logfile,
|
||||
@@ -257,7 +243,7 @@ class _TestBase(tests.LimitedTestCase):
|
||||
if 'sock' not in new_kwargs:
|
||||
new_kwargs['sock'] = eventlet.listen(('localhost', 0))
|
||||
|
||||
self.port = new_kwargs['sock'].getsockname()[1]
|
||||
self.server_addr = new_kwargs['sock'].getsockname()
|
||||
self.spawn_thread(wsgi.server, **new_kwargs)
|
||||
|
||||
def spawn_thread(self, target, **kwargs):
|
||||
@@ -281,64 +267,37 @@ class TestHttpd(_TestBase):
|
||||
self.site = Site()
|
||||
|
||||
def test_001_server(self):
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
result = fd.read()
|
||||
fd.close()
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = recvall(sock)
|
||||
# The server responds with the maximum version it supports
|
||||
assert result.startswith(b'HTTP'), result
|
||||
assert result.endswith(b'hello world'), result
|
||||
|
||||
def test_002_keepalive(self):
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
read_http(sock)
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
read_http(sock)
|
||||
fd.close()
|
||||
sock.close()
|
||||
|
||||
def test_003_passing_non_int_to_read(self):
|
||||
# This should go in greenio_test
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
cancel = eventlet.Timeout(1, RuntimeError)
|
||||
self.assertRaises(TypeError, fd.read, "This shouldn't work")
|
||||
cancel.cancel()
|
||||
fd.close()
|
||||
|
||||
def test_004_close_keepalive(self):
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
read_http(sock)
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
read_http(sock)
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result1 = read_http(sock)
|
||||
assert result1.status == 'HTTP/1.1 200 OK'
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result2 = read_http(sock)
|
||||
assert result2.status == 'HTTP/1.1 200 OK'
|
||||
assert result2.headers_lower['connection'] == 'close'
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
self.assertRaises(ConnectionClosed, read_http, sock)
|
||||
fd.close()
|
||||
|
||||
def test_006_reject_long_urls(self):
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
path_parts = []
|
||||
for ii in range(3000):
|
||||
path_parts.append('path')
|
||||
@@ -363,65 +322,48 @@ class TestHttpd(_TestBase):
|
||||
return [six.b('a is %s, body is %s' % (a, body))]
|
||||
|
||||
self.site.application = new_app
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
request = '\r\n'.join((
|
||||
'POST / HTTP/1.0',
|
||||
'Host: localhost',
|
||||
'Content-Length: 3',
|
||||
'',
|
||||
'a=a'))
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(request.encode())
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
request = b'\r\n'.join((
|
||||
b'POST / HTTP/1.0',
|
||||
b'Host: localhost',
|
||||
b'Content-Length: 3',
|
||||
b'',
|
||||
b'a=a'))
|
||||
sock.sendall(request)
|
||||
|
||||
# send some junk after the actual request
|
||||
fd.write(b'01234567890123456789')
|
||||
sock.sendall(b'01234567890123456789')
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.body, b'a is a, body is a=a')
|
||||
fd.close()
|
||||
|
||||
def test_008_correctresponse(self):
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result_200 = read_http(sock)
|
||||
fd.write(b'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET /notexist HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
read_http(sock)
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result_test = read_http(sock)
|
||||
self.assertEqual(result_200.status, result_test.status)
|
||||
fd.close()
|
||||
sock.close()
|
||||
|
||||
def test_009_chunked_response(self):
|
||||
self.site.application = chunked_app
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
assert b'Transfer-Encoding: chunked' in fd.read()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
assert b'Transfer-Encoding: chunked' in recvall(sock)
|
||||
|
||||
def test_010_no_chunked_http_1_0(self):
|
||||
self.site.application = chunked_app
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
assert b'Transfer-Encoding: chunked' not in fd.read()
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
assert b'Transfer-Encoding: chunked' not in recvall(sock)
|
||||
|
||||
def test_011_multiple_chunks(self):
|
||||
self.site.application = big_chunks
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
@@ -461,7 +403,7 @@ class TestHttpd(_TestBase):
|
||||
#
|
||||
# Related CPython issue: "Raw I/O writelines() broken",
|
||||
# http://bugs.python.org/issue26292
|
||||
|
||||
#
|
||||
# Custom accept() and send() in order to simulate a connection that
|
||||
# only sends one byte at a time so that any code that doesn't handle
|
||||
# partial writes correctly has to fail.
|
||||
@@ -473,8 +415,7 @@ class TestHttpd(_TestBase):
|
||||
original_send = connection.send
|
||||
|
||||
def send(b, *args):
|
||||
if b:
|
||||
b = b[0:1]
|
||||
b = b[:1]
|
||||
return original_send(b, *args)
|
||||
|
||||
connection.send = send
|
||||
@@ -490,16 +431,11 @@ class TestHttpd(_TestBase):
|
||||
|
||||
self.spawn_server(sock=listen_socket)
|
||||
self.site.application = application
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
|
||||
# This would previously hang forever
|
||||
result = read_http(sock)
|
||||
|
||||
# Just to be sure we actually read what we wanted
|
||||
eq_(result.body, b'asd')
|
||||
assert result.body == b'asd'
|
||||
|
||||
@tests.skip_if_no_ssl
|
||||
def test_012_ssl_server(self):
|
||||
@@ -516,7 +452,7 @@ class TestHttpd(_TestBase):
|
||||
server_side=True)
|
||||
self.spawn_server(sock=server_sock, site=wsgi_app)
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock = eventlet.wrap_ssl(sock)
|
||||
sock.write(
|
||||
b'POST /foo HTTP/1.1\r\nHost: localhost\r\n'
|
||||
@@ -546,7 +482,7 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_014_chunked_post(self):
|
||||
self.site.application = chunked_post
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write('PUT /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||
'Transfer-Encoding: chunked\r\n\r\n'
|
||||
@@ -558,7 +494,7 @@ class TestHttpd(_TestBase):
|
||||
response = fd.read()
|
||||
assert response == b'oh hai', 'invalid response %s' % response
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write('PUT /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||
'Transfer-Encoding: chunked\r\n\r\n'
|
||||
@@ -570,7 +506,7 @@ class TestHttpd(_TestBase):
|
||||
response = fd.read()
|
||||
assert response == b'oh hai', 'invalid response %s' % response
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write('PUT /c HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
|
||||
'Transfer-Encoding: chunked\r\n\r\n'
|
||||
@@ -584,17 +520,13 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_015_write(self):
|
||||
self.site.application = use_write
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result1 = read_http(sock)
|
||||
assert 'content-length' in result1.headers_lower
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET /b HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result2 = read_http(sock)
|
||||
assert 'transfer-encoding' in result2.headers_lower
|
||||
assert result2.headers_lower['transfer-encoding'] == 'chunked'
|
||||
@@ -607,7 +539,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Length', '7')])
|
||||
return [b'testing']
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET /a HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
@@ -659,19 +591,15 @@ class TestHttpd(_TestBase):
|
||||
def test_018_http_10_keepalive(self):
|
||||
# verify that if an http/1.0 client sends connection: keep-alive
|
||||
# that we don't close the connection
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
result1 = read_http(sock)
|
||||
assert 'connection' in result1.headers_lower
|
||||
self.assertEqual('keep-alive', result1.headers_lower['connection'])
|
||||
|
||||
# repeat request to verify connection is actually still open
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
result2 = read_http(sock)
|
||||
assert 'connection' in result2.headers_lower
|
||||
self.assertEqual('keep-alive', result2.headers_lower['connection'])
|
||||
@@ -684,18 +612,15 @@ class TestHttpd(_TestBase):
|
||||
return [b'hello!']
|
||||
|
||||
self.site.application = use_fieldstorage
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write('POST / HTTP/1.1\r\n'
|
||||
'Host: localhost\r\n'
|
||||
'Connection: close\r\n'
|
||||
'Transfer-Encoding: chunked\r\n\r\n'
|
||||
'2\r\noh\r\n'
|
||||
'4\r\n hai\r\n0\r\n\r\n'.encode())
|
||||
fd.flush()
|
||||
assert b'hello!' in fd.read()
|
||||
sock.sendall(b'POST / HTTP/1.1\r\n'
|
||||
b'Host: localhost\r\n'
|
||||
b'Connection: close\r\n'
|
||||
b'Transfer-Encoding: chunked\r\n\r\n'
|
||||
b'2\r\noh\r\n'
|
||||
b'4\r\n hai\r\n0\r\n\r\n')
|
||||
assert b'hello!' in recvall(sock)
|
||||
|
||||
def test_020_x_forwarded_for(self):
|
||||
request_bytes = (
|
||||
@@ -703,7 +628,7 @@ class TestHttpd(_TestBase):
|
||||
+ b'X-Forwarded-For: 1.2.3.4, 5.6.7.8\r\n\r\n'
|
||||
)
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(request_bytes)
|
||||
sock.recv(1024)
|
||||
sock.close()
|
||||
@@ -713,7 +638,7 @@ class TestHttpd(_TestBase):
|
||||
self.logfile = six.StringIO()
|
||||
self.spawn_server(log_x_forwarded_for=False)
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(request_bytes)
|
||||
sock.recv(1024)
|
||||
sock.close()
|
||||
@@ -727,12 +652,9 @@ class TestHttpd(_TestBase):
|
||||
server_sock_2 = server_sock.dup()
|
||||
self.spawn_server(sock=server_sock_2)
|
||||
# do a single req/response to verify it's up
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
result = fd.read(1024)
|
||||
fd.close()
|
||||
sock = eventlet.connect(server_sock.getsockname())
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = sock.recv(1024)
|
||||
assert result.startswith(b'HTTP'), result
|
||||
assert result.endswith(b'hello world'), result
|
||||
|
||||
@@ -746,12 +668,9 @@ class TestHttpd(_TestBase):
|
||||
except socket.error as exc:
|
||||
self.assertEqual(support.get_errno(exc), errno.EBADF)
|
||||
self.spawn_server(sock=server_sock)
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
result = fd.read(1024)
|
||||
fd.close()
|
||||
sock = eventlet.connect(server_sock.getsockname())
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = sock.recv(1024)
|
||||
assert result.startswith(b'HTTP'), result
|
||||
assert result.endswith(b'hello world'), result
|
||||
|
||||
@@ -768,14 +687,12 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||
return []
|
||||
self.site.application = clobberin_time
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write('GET / HTTP/1.1\r\n'
|
||||
'Host: localhost\r\n'
|
||||
'Connection: close\r\n'
|
||||
'\r\n\r\n'.encode())
|
||||
fd.flush()
|
||||
assert b'200 OK' in fd.read()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\n'
|
||||
b'Host: localhost\r\n'
|
||||
b'Connection: close\r\n'
|
||||
b'\r\n\r\n')
|
||||
assert b'200 OK' in recvall(sock)
|
||||
|
||||
def test_022_custom_pool(self):
|
||||
# just test that it accepts the parameter for now
|
||||
@@ -785,24 +702,16 @@ class TestHttpd(_TestBase):
|
||||
self.spawn_server(custom_pool=p)
|
||||
|
||||
# this stuff is copied from test_001_server, could be better factored
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
result = fd.read()
|
||||
fd.close()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = recvall(sock)
|
||||
assert result.startswith(b'HTTP'), result
|
||||
assert result.endswith(b'hello world'), result
|
||||
|
||||
def test_023_bad_content_length(self):
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.0\r\nHost: localhost\r\nContent-length: argh\r\n\r\n')
|
||||
fd.flush()
|
||||
result = fd.read()
|
||||
fd.close()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nContent-length: argh\r\n\r\n')
|
||||
result = recvall(sock)
|
||||
assert result.startswith(b'HTTP'), result
|
||||
assert b'400 Bad Request' in result, result
|
||||
assert b'500' not in result, result
|
||||
@@ -817,7 +726,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Length', str(len(text)))])
|
||||
return [text]
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\n'
|
||||
b'Expect: 100-continue\r\n\r\n')
|
||||
@@ -863,7 +772,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Length', str(len(text)))])
|
||||
return [text]
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'PUT / HTTP/1.1\r\nHost: localhost\r\nContent-length: 1025\r\n'
|
||||
b'Expect: 100-continue\r\n\r\n')
|
||||
@@ -918,7 +827,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Length', str(len(text)))])
|
||||
return [text]
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'PUT /a HTTP/1.1\r\n'
|
||||
b'Host: localhost\r\nConnection: close\r\n'
|
||||
@@ -996,7 +905,7 @@ class TestHttpd(_TestBase):
|
||||
return [text]
|
||||
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'PUT /a HTTP/1.1\r\n'
|
||||
b'Host: localhost\r\nConnection: close\r\n'
|
||||
@@ -1065,7 +974,7 @@ class TestHttpd(_TestBase):
|
||||
self.spawn_server(sock=listener)
|
||||
eventlet.sleep(0) # need to enter server loop
|
||||
try:
|
||||
eventlet.connect(('localhost', self.port))
|
||||
eventlet.connect(self.server_addr)
|
||||
self.fail("Didn't expect to connect")
|
||||
except socket.error as exc:
|
||||
self.assertEqual(support.get_errno(exc), errno.ECONNREFUSED)
|
||||
@@ -1076,7 +985,7 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_026_log_format(self):
|
||||
self.spawn_server(log_format="HI %(request_line)s HI")
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET /yo! HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
sock.recv(1024)
|
||||
sock.close()
|
||||
@@ -1087,7 +996,7 @@ class TestHttpd(_TestBase):
|
||||
# and we're not speaking with a 1.1 client, that we
|
||||
# close the connection
|
||||
self.site.application = chunked_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
|
||||
@@ -1103,7 +1012,7 @@ class TestHttpd(_TestBase):
|
||||
return iter([b"stuff", b"", b"more stuff"])
|
||||
|
||||
self.site.application = empty_string_chunked_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
|
||||
@@ -1115,7 +1024,7 @@ class TestHttpd(_TestBase):
|
||||
start_size = wsgi.HttpProtocol.minimum_chunk_size
|
||||
|
||||
self.spawn_server(minimum_chunk_size=start_size * 2)
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
read_http(sock)
|
||||
|
||||
@@ -1127,7 +1036,7 @@ class TestHttpd(_TestBase):
|
||||
self.spawn_server(minimum_chunk_size=1)
|
||||
|
||||
self.site.application = chunked_fail_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
|
||||
@@ -1146,8 +1055,7 @@ class TestHttpd(_TestBase):
|
||||
# verify that if an http/1.0 client sends connection: keep-alive
|
||||
# and the server doesn't accept keep-alives, we close the connection
|
||||
self.spawn_server(keepalive=False)
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
@@ -1155,22 +1063,17 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_027_keepalive_chunked(self):
|
||||
self.site.application = chunked_post
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('wb')
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
common_suffix = (
|
||||
b'Host: localhost\r\nTransfer-Encoding: chunked\r\n\r\n' +
|
||||
b'10\r\n0123456789abcdef\r\n0\r\n\r\n')
|
||||
fd.write(b'PUT /a HTTP/1.1\r\n' + common_suffix)
|
||||
fd.flush()
|
||||
sock.sendall(b'PUT /a HTTP/1.1\r\n' + common_suffix)
|
||||
read_http(sock)
|
||||
fd.write(b'PUT /b HTTP/1.1\r\n' + common_suffix)
|
||||
fd.flush()
|
||||
sock.sendall(b'PUT /b HTTP/1.1\r\n' + common_suffix)
|
||||
read_http(sock)
|
||||
fd.write(b'PUT /c HTTP/1.1\r\n' + common_suffix)
|
||||
fd.flush()
|
||||
sock.sendall(b'PUT /c HTTP/1.1\r\n' + common_suffix)
|
||||
read_http(sock)
|
||||
fd.write(b'PUT /a HTTP/1.1\r\n' + common_suffix)
|
||||
fd.flush()
|
||||
sock.sendall(b'PUT /a HTTP/1.1\r\n' + common_suffix)
|
||||
read_http(sock)
|
||||
sock.close()
|
||||
|
||||
@@ -1192,9 +1095,9 @@ class TestHttpd(_TestBase):
|
||||
eventlet.listen(('localhost', 0)),
|
||||
certfile=certificate_file, keyfile=private_key_file,
|
||||
server_side=True)
|
||||
port = srv_sock.getsockname()[1]
|
||||
addr = srv_sock.getsockname()
|
||||
g = eventlet.spawn_n(server, srv_sock)
|
||||
client = eventlet.connect(('localhost', port))
|
||||
client = eventlet.connect(addr)
|
||||
if data: # send non-ssl request
|
||||
client.sendall(data.encode())
|
||||
else: # close sock prematurely
|
||||
@@ -1203,7 +1106,7 @@ class TestHttpd(_TestBase):
|
||||
assert not errored[0], errored[0]
|
||||
# make another request to ensure the server's still alive
|
||||
try:
|
||||
client = ssl.wrap_socket(eventlet.connect(('localhost', port)))
|
||||
client = ssl.wrap_socket(eventlet.connect(addr))
|
||||
client.write(b'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n')
|
||||
result = recvall(client)
|
||||
assert result.startswith(b'HTTP'), result
|
||||
@@ -1235,7 +1138,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Type', 'text/plain')])
|
||||
yield b''
|
||||
self.site.application = one_posthook_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fp = sock.makefile('rwb')
|
||||
fp.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fp.flush()
|
||||
@@ -1258,7 +1161,7 @@ class TestHttpd(_TestBase):
|
||||
start_response('200 OK', [('Content-Type', 'text/plain')])
|
||||
yield b''
|
||||
self.site.application = two_posthook_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
fp = sock.makefile('rwb')
|
||||
fp.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fp.flush()
|
||||
@@ -1269,7 +1172,7 @@ class TestHttpd(_TestBase):
|
||||
self.assertEqual(posthook2_count[0], 25)
|
||||
|
||||
def test_030_reject_long_header_lines(self):
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
request = 'GET / HTTP/1.0\r\nHost: localhost\r\nLong: %s\r\n\r\n' % \
|
||||
('a' * 10000)
|
||||
send_expect_close(sock, request.encode())
|
||||
@@ -1277,7 +1180,7 @@ class TestHttpd(_TestBase):
|
||||
self.assertEqual(result.status, 'HTTP/1.0 400 Header Line Too Long')
|
||||
|
||||
def test_031_reject_large_headers(self):
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
headers = ('Name: %s\r\n' % ('a' * 7000,)) * 20
|
||||
request = 'GET / HTTP/1.0\r\nHost: localhost\r\n%s\r\n\r\n' % headers
|
||||
send_expect_close(sock, request.encode())
|
||||
@@ -1303,13 +1206,10 @@ class TestHttpd(_TestBase):
|
||||
'Host: localhost\r\n'
|
||||
'Content-Length: %i\r\n\r\n%s'
|
||||
) % (len(upload_data), bytes_to_str(upload_data))
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(request.encode())
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(request.encode())
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.body, upload_data)
|
||||
fd.close()
|
||||
self.assertEqual(g[0], 1)
|
||||
|
||||
def test_zero_length_chunked_response(self):
|
||||
@@ -1318,13 +1218,10 @@ class TestHttpd(_TestBase):
|
||||
yield b""
|
||||
|
||||
self.site.application = zero_chunked_app
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
response = fd.read().split(b'\r\n')
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
response = recvall(sock).split(b'\r\n')
|
||||
headers = []
|
||||
while True:
|
||||
h = response.pop(0)
|
||||
@@ -1338,8 +1235,7 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_configurable_url_length_limit(self):
|
||||
self.spawn_server(url_length_limit=20000)
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
path = 'x' * 15000
|
||||
request = 'GET /%s HTTP/1.0\r\nHost: localhost\r\n\r\n' % path
|
||||
fd = sock.makefile('rwb')
|
||||
@@ -1366,6 +1262,7 @@ class TestHttpd(_TestBase):
|
||||
read_content.send(content)
|
||||
start_response('200 OK', [('Content-Type', 'text/plain')])
|
||||
return [content]
|
||||
|
||||
self.site.application = chunk_reader
|
||||
expected_body = 'a bunch of stuff'
|
||||
data = "\r\n".join(['PUT /somefile HTTP/1.0',
|
||||
@@ -1374,7 +1271,7 @@ class TestHttpd(_TestBase):
|
||||
'def',
|
||||
expected_body])
|
||||
# start PUT-ing some chunked data but close prematurely
|
||||
sock = eventlet.connect(('127.0.0.1', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(data.encode())
|
||||
sock.close()
|
||||
# the test passes if we successfully get here, and read all the data
|
||||
@@ -1406,7 +1303,7 @@ class TestHttpd(_TestBase):
|
||||
'db',
|
||||
expected_body])
|
||||
# start PUT-ing some chunked data but close prematurely
|
||||
sock = eventlet.connect(('127.0.0.1', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(data.encode())
|
||||
sock.close()
|
||||
# the test passes if we successfully get here, and read all the data
|
||||
@@ -1438,7 +1335,7 @@ class TestHttpd(_TestBase):
|
||||
'cats',
|
||||
expected_body])
|
||||
# start PUT-ing some garbage
|
||||
sock = eventlet.connect(('127.0.0.1', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(data.encode())
|
||||
sock.close()
|
||||
# the test passes if we successfully get here, and read all the data
|
||||
@@ -1450,10 +1347,8 @@ class TestHttpd(_TestBase):
|
||||
def wsgi_app(environ, start_response):
|
||||
raise RuntimeError("intentional error")
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.status, 'HTTP/1.1 500 Internal Server Error')
|
||||
self.assertEqual(result.headers_lower['connection'], 'close')
|
||||
@@ -1465,10 +1360,8 @@ class TestHttpd(_TestBase):
|
||||
yield b"oh hai, "
|
||||
yield u"xxx"
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
assert b'xxx' in result.body
|
||||
|
||||
@@ -1478,10 +1371,8 @@ class TestHttpd(_TestBase):
|
||||
yield b"oh hai, "
|
||||
yield u"xxx \u0230"
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.status, 'HTTP/1.1 500 Internal Server Error')
|
||||
self.assertEqual(result.headers_lower['connection'], 'close')
|
||||
@@ -1492,10 +1383,8 @@ class TestHttpd(_TestBase):
|
||||
yield six.b("decoded: %s" % environ['PATH_INFO'])
|
||||
yield six.b("raw: %s" % environ['RAW_PATH_INFO'])
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET /a*b@%40%233 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET /a*b@%40%233 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.status, 'HTTP/1.1 200 OK')
|
||||
assert b'decoded: /a*b@@#3' in result.body
|
||||
@@ -1531,10 +1420,8 @@ class TestHttpd(_TestBase):
|
||||
raise RuntimeError("intentional crash")
|
||||
self.site.application = crasher
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result1 = read_http(sock)
|
||||
self.assertEqual(result1.status, 'HTTP/1.1 500 Internal Server Error')
|
||||
self.assertEqual(result1.body, b'')
|
||||
@@ -1544,10 +1431,8 @@ class TestHttpd(_TestBase):
|
||||
# verify traceback when debugging enabled
|
||||
self.spawn_server(debug=True)
|
||||
self.site.application = crasher
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('wb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result2 = read_http(sock)
|
||||
self.assertEqual(result2.status, 'HTTP/1.1 500 Internal Server Error')
|
||||
assert b'intentional crash' in result2.body, result2.body
|
||||
@@ -1564,7 +1449,7 @@ class TestHttpd(_TestBase):
|
||||
yield b'a' * 9876
|
||||
|
||||
server_sock = eventlet.listen(('localhost', 0))
|
||||
self.port = server_sock.getsockname()[1]
|
||||
self.server_addr = server_sock.getsockname()
|
||||
server = wsgi.Server(server_sock, server_sock.getsockname(), long_response,
|
||||
log=self.logfile)
|
||||
|
||||
@@ -1588,7 +1473,7 @@ class TestHttpd(_TestBase):
|
||||
|
||||
def test_server_socket_timeout(self):
|
||||
self.spawn_server(socket_timeout=0.1)
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.send(b'GET / HTTP/1.1\r\n')
|
||||
eventlet.sleep(0.1)
|
||||
try:
|
||||
@@ -1609,7 +1494,7 @@ class TestHttpd(_TestBase):
|
||||
|
||||
self.spawn_server(site=wsgi_app, capitalize_response_headers=False)
|
||||
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
sock.close()
|
||||
@@ -1670,18 +1555,14 @@ class IterableAlreadyHandledTest(_TestBase):
|
||||
|
||||
def test_iterable_app_keeps_socket_open_unless_connection_close_sent(self):
|
||||
self.site.application = self.get_app()
|
||||
sock = eventlet.connect(
|
||||
('localhost', self.port))
|
||||
sock = eventlet.connect(self.server_addr)
|
||||
|
||||
fd = sock.makefile('rwb')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
|
||||
fd.flush()
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
response_line, headers = read_headers(sock)
|
||||
self.assertEqual(response_line, 'HTTP/1.1 200 OK\r\n')
|
||||
assert 'connection' not in headers
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
fd.flush()
|
||||
|
||||
sock.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n')
|
||||
result = read_http(sock)
|
||||
self.assertEqual(result.status, 'HTTP/1.1 200 OK')
|
||||
self.assertEqual(result.headers_lower.get('transfer-encoding'), 'chunked')
|
||||
@@ -1743,7 +1624,7 @@ class TestChunkedInput(_TestBase):
|
||||
return response
|
||||
|
||||
def connect(self):
|
||||
return eventlet.connect(('localhost', self.port))
|
||||
return eventlet.connect(self.server_addr)
|
||||
|
||||
def set_site(self):
|
||||
self.site = Site()
|
||||
|
Reference in New Issue
Block a user