From a05fa9e7f61b6af0170d3a86c9117c5c5baff642 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 22 Jun 2017 21:54:00 +0300 Subject: [PATCH] Use popall instead of in/del pair (#2002) --- aiohttp/connector.py | 5 ++--- aiohttp/formdata.py | 2 +- aiohttp/web_response.py | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/aiohttp/connector.py b/aiohttp/connector.py index 2cb2e9d2485..86c44c7358b 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -750,9 +750,8 @@ def _create_proxy_connection(self, req): except OSError as exc: raise ClientProxyConnectionError(*exc.args) from exc - if hdrs.AUTHORIZATION in proxy_req.headers: - auth = proxy_req.headers[hdrs.AUTHORIZATION] - del proxy_req.headers[hdrs.AUTHORIZATION] + auth = proxy_req.headers.pop(hdrs.AUTHORIZATION, None) + if auth is not None: if not req.ssl: req.headers[hdrs.PROXY_AUTHORIZATION] = auth else: diff --git a/aiohttp/formdata.py b/aiohttp/formdata.py index a5effd7df73..0f2b5ff4a13 100644 --- a/aiohttp/formdata.py +++ b/aiohttp/formdata.py @@ -130,7 +130,7 @@ def _gen_form_data(self): ) # FIXME cgi.FieldStorage doesn't likes body parts with # Content-Length which were sent via chunked transfer encoding - part.headers.pop(hdrs.CONTENT_LENGTH, None) + part.headers.popall(hdrs.CONTENT_LENGTH, None) self._writer.append_payload(part) diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index 1feec8fa089..d7d80face49 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -302,8 +302,7 @@ def _do_start_compression(self, coding): self._payload_writer.enable_compression(coding.value) # Compressed payload may have different content length, # remove the header - if hdrs.CONTENT_LENGTH in self._headers: - del self._headers[hdrs.CONTENT_LENGTH] + self._headers.popall(hdrs.CONTENT_LENGTH, None) def _start_compression(self, request): if self._compression_force: