From 42ec81df905713045e69e2add4bb5787d89eab2f Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Thu, 16 Jul 2020 11:22:58 -0500 Subject: [PATCH] Collapse request chunked data and framing into one send() call (#1906) --- src/urllib3/connection.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py index 7e086312ce..cf9cfee9a1 100644 --- a/src/urllib3/connection.py +++ b/src/urllib3/connection.py @@ -240,10 +240,11 @@ def request_chunked(self, method, url, body=None, headers=None): if not isinstance(chunk, bytes): chunk = chunk.encode("utf8") len_str = hex(len(chunk))[2:] - self.send(len_str.encode("utf-8")) - self.send(b"\r\n") - self.send(chunk) - self.send(b"\r\n") + to_send = bytearray(len_str.encode()) + to_send += b"\r\n" + to_send += chunk + to_send += b"\r\n" + self.send(to_send) # After the if clause, to always have a closed body self.send(b"0\r\n\r\n")