diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index 79250e0..275c0e9 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -3,6 +3,7 @@ import os import sys import time import traceback +import types import warnings from eventlet.green import urllib @@ -424,6 +425,9 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): < self.environ['eventlet.input'].content_length): ## Read and discard body if there was no pending 100-continue if not self.environ['eventlet.input'].wfile: + # NOTE: MINIMUM_CHUNK_SIZE is used here for purpose different than chunking. + # We use it only cause it's at hand and has reasonable value in terms of + # emptying the buffer. while self.environ['eventlet.input'].read(MINIMUM_CHUNK_SIZE): pass finish = time.time() @@ -546,8 +550,7 @@ class Server(BaseHTTPServer.HTTPServer): self.max_http_version = max_http_version self.protocol = protocol self.pid = os.getpid() - if minimum_chunk_size is not None: - protocol.minimum_chunk_size = minimum_chunk_size + self.minimum_chunk_size = minimum_chunk_size self.log_x_forwarded_for = log_x_forwarded_for self.log_output = log_output self.log_format = log_format @@ -572,8 +575,13 @@ class Server(BaseHTTPServer.HTTPServer): return d def process_request(self, (socket, address)): - proto = self.protocol(socket, address, self) - proto.handle() + # The actual request handling takes place in __init__, so we need to + # set minimum_chunk_size before __init__ executes and we don't want to modify + # class variable + proto = types.InstanceType(self.protocol) + if self.minimum_chunk_size is not None: + proto.minimum_chunk_size = self.minimum_chunk_size + proto.__init__(socket, address, self) def log_message(self, message): self.log.write(message + '\n') diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index d03c061..3f80188 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -786,10 +786,18 @@ class TestHttpd(_TestBase): self.assertNotEqual(headers.get('transfer-encoding'), 'chunked') self.assertEquals(body, "thisischunked") + def test_minimum_chunk_size_parameter_leaves_httpprotocol_class_member_intact(self): + start_size = wsgi.HttpProtocol.minimum_chunk_size + + self.spawn_server(minimum_chunk_size=start_size * 2) + sock = eventlet.connect(('localhost', self.port)) + sock.sendall('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') + read_http(sock) + + self.assertEqual(wsgi.HttpProtocol.minimum_chunk_size, start_size) + def test_error_in_chunked_closes_connection(self): # From http://rhodesmill.org/brandon/2013/chunked-wsgi/ - greenthread.kill(self.killer) - eventlet.sleep(0) self.spawn_server(minimum_chunk_size=1) self.site.application = chunked_fail_app