wsgi: minimum_chunk_size of last Server altered all previous (global variable)

This commit is contained in:
Jakub Stasiak
2013-04-04 05:07:16 +01:00
committed by Sergey Shepelev
parent 22e8f4fc75
commit 1c243a4af2
2 changed files with 22 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ import os
import sys import sys
import time import time
import traceback import traceback
import types
import warnings import warnings
from eventlet.green import urllib from eventlet.green import urllib
@@ -424,6 +425,9 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler):
< self.environ['eventlet.input'].content_length): < self.environ['eventlet.input'].content_length):
## Read and discard body if there was no pending 100-continue ## Read and discard body if there was no pending 100-continue
if not self.environ['eventlet.input'].wfile: 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): while self.environ['eventlet.input'].read(MINIMUM_CHUNK_SIZE):
pass pass
finish = time.time() finish = time.time()
@@ -546,8 +550,7 @@ class Server(BaseHTTPServer.HTTPServer):
self.max_http_version = max_http_version self.max_http_version = max_http_version
self.protocol = protocol self.protocol = protocol
self.pid = os.getpid() self.pid = os.getpid()
if minimum_chunk_size is not None: self.minimum_chunk_size = minimum_chunk_size
protocol.minimum_chunk_size = minimum_chunk_size
self.log_x_forwarded_for = log_x_forwarded_for self.log_x_forwarded_for = log_x_forwarded_for
self.log_output = log_output self.log_output = log_output
self.log_format = log_format self.log_format = log_format
@@ -572,8 +575,13 @@ class Server(BaseHTTPServer.HTTPServer):
return d return d
def process_request(self, (socket, address)): def process_request(self, (socket, address)):
proto = self.protocol(socket, address, self) # The actual request handling takes place in __init__, so we need to
proto.handle() # 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): def log_message(self, message):
self.log.write(message + '\n') self.log.write(message + '\n')

View File

@@ -786,10 +786,18 @@ class TestHttpd(_TestBase):
self.assertNotEqual(headers.get('transfer-encoding'), 'chunked') self.assertNotEqual(headers.get('transfer-encoding'), 'chunked')
self.assertEquals(body, "thisischunked") 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): def test_error_in_chunked_closes_connection(self):
# From http://rhodesmill.org/brandon/2013/chunked-wsgi/ # From http://rhodesmill.org/brandon/2013/chunked-wsgi/
greenthread.kill(self.killer)
eventlet.sleep(0)
self.spawn_server(minimum_chunk_size=1) self.spawn_server(minimum_chunk_size=1)
self.site.application = chunked_fail_app self.site.application = chunked_fail_app