diff --git a/swift/common/middleware/bulk.py b/swift/common/middleware/bulk.py index d3301c39ea..29136b9d55 100644 --- a/swift/common/middleware/bulk.py +++ b/swift/common/middleware/bulk.py @@ -387,6 +387,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) @@ -407,7 +408,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: @@ -515,6 +515,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) @@ -534,7 +535,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 feab2dd0c9..a0328134a1 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): @@ -627,8 +629,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):