Patch for wsgi http/1.0 keepalive from Brian Brunswick. Added unit test to ensure this keeps working.

This commit is contained in:
Ryan Williams
2009-09-28 14:22:48 -07:00
parent 252dcad98e
commit f36908a01e
2 changed files with 25 additions and 5 deletions

View File

@@ -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')

View File

@@ -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__':