diff --git a/swift/common/middleware/bulk.py b/swift/common/middleware/bulk.py index 72f472f003..dae5026a33 100644 --- a/swift/common/middleware/bulk.py +++ b/swift/common/middleware/bulk.py @@ -379,6 +379,7 @@ class Bulk(object): 'Response Body': '', 'Number Deleted': 0, 'Number Not Found': 0} + req.environ['eventlet.minimum_write_chunk_size'] = 0 try: if not out_content_type: raise HTTPNotAcceptable(request=req) @@ -399,7 +400,6 @@ class Bulk(object): if objs_to_delete is None: objs_to_delete = self.get_objs_to_delete(req) failed_file_response = {'type': HTTPBadRequest} - req.environ['eventlet.minimum_write_chunk_size'] = 0 def delete_filter(predicate, objs_to_delete): for obj_to_delete in objs_to_delete: @@ -507,6 +507,7 @@ class Bulk(object): last_yield = time() separator = '' containers_accessed = set() + req.environ['eventlet.minimum_write_chunk_size'] = 0 try: if not out_content_type: raise HTTPNotAcceptable(request=req) @@ -526,7 +527,6 @@ class Bulk(object): tar = tarfile.open(mode='r|' + compress_type, fileobj=req.body_file) failed_response_type = HTTPBadRequest - req.environ['eventlet.minimum_write_chunk_size'] = 0 containers_created = 0 while True: if last_yield + self.yield_frequency < time(): diff --git a/test/unit/common/middleware/test_bulk.py b/test/unit/common/middleware/test_bulk.py index dc9be5647c..1758d0ac82 100644 --- a/test/unit/common/middleware/test_bulk.py +++ b/test/unit/common/middleware/test_bulk.py @@ -243,9 +243,11 @@ class TestUntar(unittest.TestCase): def handle_extract_and_iter(self, req, compress_format, out_content_type='application/json'): - resp_body = ''.join( - self.bulk.handle_extract_iter(req, compress_format, - out_content_type=out_content_type)) + iter = self.bulk.handle_extract_iter( + req, compress_format, out_content_type=out_content_type) + first_chunk = next(iter) + self.assertEqual(req.environ['eventlet.minimum_write_chunk_size'], 0) + resp_body = first_chunk + ''.join(iter) return resp_body def test_create_container_for_path(self): @@ -623,8 +625,11 @@ class TestDelete(unittest.TestCase): self.app.delete_paths = [] def handle_delete_and_iter(self, req, out_content_type='application/json'): - resp_body = ''.join(self.bulk.handle_delete_iter( - req, out_content_type=out_content_type)) + iter = self.bulk.handle_delete_iter( + req, out_content_type=out_content_type) + first_chunk = next(iter) + self.assertEqual(req.environ['eventlet.minimum_write_chunk_size'], 0) + resp_body = first_chunk + ''.join(iter) return resp_body def test_bulk_delete_uses_predefined_object_errors(self):