diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index 50e70a4..ca660a3 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -230,8 +230,12 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): if 'date' not in header_list: towrite.append('Date: %s\r\n' % (format_date_time(time.time()),)) if self.request_version == 'HTTP/1.0': - towrite.append('Connection: close\r\n') - self.close_connection = 1 + if self.headers.get('Connection', "").lower() == 'keep-alive': + towrite.append('Connection: keep-alive\r\n') + self.close_connection = 0 + else: + towrite.append('Connection: close\r\n') + self.close_connection = 1 elif 'content-length' not in header_list: use_chunked[0] = True towrite.append('Transfer-Encoding: chunked\r\n') diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 629ec06..6bfbbe1 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -22,8 +22,8 @@ import cgi import os -from tests import skipped -from unittest import TestCase, main +from tests import skipped, LimitedTestCase +from unittest import main from eventlet import api from eventlet import util @@ -125,7 +125,7 @@ def read_http(sock): return response_line, headers, body -class TestHttpd(TestCase): +class TestHttpd(LimitedTestCase): mode = 'static' def setUp(self): self.logfile = StringIO() @@ -426,6 +426,22 @@ class TestHttpd(TestCase): success = server_coro.wait() self.assert_(success) + + 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 = api.connect_tcp( + ('127.0.0.1', 12346)) + + fd = sock.makeGreenFile() + fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n') + self.assert_('connection: keep-alive' in + fd.readuntil('\r\n\r\n').lower()) + # repeat request to verify connection is actually still open + fd.write('GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n') + self.assert_('connection: keep-alive' in + fd.readuntil('\r\n\r\n').lower()) + if __name__ == '__main__':