From 57509ad8f8f5cf2f522a60f9609af49ac47b4ebc Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 7 Jan 2016 23:24:47 +0200 Subject: [PATCH] Fix #271: Memory leak in request --- CHANGES.txt | 2 +- aiohttp/__init__.py | 2 +- aiohttp/client_reqrep.py | 6 ++---- aiohttp/protocol.py | 6 ++---- aiohttp/server.py | 13 ++++++------- aiohttp/wsgi.py | 3 ++- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 63ab559a3bf..db31c6d3d2d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,7 +1,7 @@ CHANGES ======= -0.21.0 (XX-XX-XXXX) +0.20.2 (01-07-2015) -------------------- - Enable use of `await` for a class based view #717 diff --git a/aiohttp/__init__.py b/aiohttp/__init__.py index bb5f20a1c59..fb05bb0ff85 100644 --- a/aiohttp/__init__.py +++ b/aiohttp/__init__.py @@ -1,6 +1,6 @@ # This relies on each of the submodules having an __all__ variable. -__version__ = '0.21.0a0' +__version__ = '0.20.2' from . import hdrs # noqa diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index 51205ec89d5..fac76af9fdb 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -473,10 +473,8 @@ def send(self, writer, reader): hdrs.CONTENT_TYPE not in self.headers): self.headers[hdrs.CONTENT_TYPE] = 'application/octet-stream' - request.add_headers( - *((k, v) - for k, v in ((k, value) - for k, value in self.headers.items()))) + for k, value in self.headers.items(): + request.add_header(k, value) request.send_headers() self._writer = helpers.ensure_future( diff --git a/aiohttp/protocol.py b/aiohttp/protocol.py index 7dc78d7a89b..295306d32a8 100644 --- a/aiohttp/protocol.py +++ b/aiohttp/protocol.py @@ -3,7 +3,6 @@ import collections import functools import http.server -import itertools import re import string import sys @@ -661,9 +660,8 @@ def send_headers(self, _sep=': ', _end='\r\n'): self._add_default_headers() # status + headers - headers = ''.join(itertools.chain( - (self.status_line,), - *((k, _sep, v, _end) for k, v in self.headers.items()))) + headers = self.status_line + ''.join( + [k + _sep + v + _end for k, v in self.headers.items()]) headers = headers.encode('utf-8') + b'\r\n' self.output_length += len(headers) diff --git a/aiohttp/server.py b/aiohttp/server.py index bf00d1463c8..c160b1403ee 100644 --- a/aiohttp/server.py +++ b/aiohttp/server.py @@ -351,11 +351,11 @@ def handle_error(self, status=500, message=None, status=status, reason=reason, message=msg).encode('utf-8') response = aiohttp.Response(self.writer, status, close=True) - response.add_headers( - ('CONTENT-TYPE', 'text/html; charset=utf-8'), - ('CONTENT-LENGTH', str(len(html)))) + response.add_header(hdrs.CONTENT_TYPE, 'text/html; charset=utf-8') + response.add_header(hdrs.CONTENT_LENGTH, str(len(html))) if headers is not None: - response.add_headers(*headers) + for name, value in headers: + response.add_header(name, value) response.send_headers() response.write(html) @@ -385,9 +385,8 @@ def handle_request(self, message, payload): body = b'Page Not Found!' - response.add_headers( - ('CONTENT-TYPE', 'text/plain'), - ('CONTENT-LENGTH', str(len(body)))) + response.add_header(hdrs.CONTENT_TYPE, 'text/plain') + response.add_header(hdrs.CONTENT_LENGTH, str(len(body))) response.send_headers() response.write(body) drain = response.write_eof() diff --git a/aiohttp/wsgi.py b/aiohttp/wsgi.py index e02bde48995..cf76c4e9e9e 100644 --- a/aiohttp/wsgi.py +++ b/aiohttp/wsgi.py @@ -220,7 +220,8 @@ def start_response(self, status, headers, exc_info=None): self.writer, status_code, self.message.version, self.message.should_close) resp.HOP_HEADERS = self.HOP_HEADERS - resp.add_headers(*headers) + for name, value in headers: + resp.add_header(name, value) if resp.has_chunked_hdr: resp.enable_chunked_encoding()