wsgi: minimum_chunk_size of last Server altered all previous (global variable)
This commit is contained in:

committed by
Sergey Shepelev

parent
22e8f4fc75
commit
1c243a4af2
@@ -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')
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user