From dd8302f1fb9eae285164d1162e0e131800869c5c Mon Sep 17 00:00:00 2001 From: nr Date: Thu, 14 Feb 2019 01:26:37 +0700 Subject: [PATCH 1/4] bpo-5038: http lib, seek to the beginning of mmap'ed file seek file pointer to the beginning of the file for mmap'ed message bodies after the file has been fully read by http client when sending requests, this ensures that the file contents can be read in subsequent requests. --- Lib/http/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/http/client.py b/Lib/http/client.py index 5aa178d7b127d9..9b57128b9b0a52 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -1023,6 +1023,7 @@ def _send_output(self, message_body=None, encode_chunked=False): # is needed to allow the current position of mmap'ed # files to be taken into account. chunks = self._read_readable(message_body) + message_body.seek(0) else: try: # this is solely to check to see if message_body From 2f2d9c01ce7639c48b8a4ee6702560fdeb74a775 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Wed, 13 Feb 2019 18:51:32 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-02-13-18-51-31.bpo-5038.NWt7FW.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-02-13-18-51-31.bpo-5038.NWt7FW.rst diff --git a/Misc/NEWS.d/next/Library/2019-02-13-18-51-31.bpo-5038.NWt7FW.rst b/Misc/NEWS.d/next/Library/2019-02-13-18-51-31.bpo-5038.NWt7FW.rst new file mode 100644 index 00000000000000..b291779afc9b52 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-02-13-18-51-31.bpo-5038.NWt7FW.rst @@ -0,0 +1,2 @@ +http lib allows mmap'ed files to be resent when the http server responds with 401 unauthorized or similar initial responses +and the requests has to be resend. \ No newline at end of file From 0ad43f1ea0768a5dfb9614c2be165333dcd4c205 Mon Sep 17 00:00:00 2001 From: wiz-1 Date: Sat, 16 Feb 2019 02:38:05 +0700 Subject: [PATCH 3/4] add testcase --- Lib/test/test_urllib2_localnet.py | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 77dec0ce713ccb..3ca3f8be29e40b 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -238,7 +238,27 @@ def do_GET(self): # Request Unauthorized self.do_AUTHHEAD() - + def do_POST(self): + if not self.headers.get("Authorization", ""): + self.do_AUTHHEAD() + self.wfile.write(b"No Auth header received") + elif self.headers.get( + "Authorization", "") == "Basic " + self.ENCODED_AUTH: + encoding = self.headers.get("Transfer-Encoding") + if encoding is None: + length = int(self.headers.get("Content-Length")) + else: + assert encoding == "chunked" + length = int(self.rfile.readline(), 16) + request = self.rfile.read(length) + assert len(request) == length + if length > 0: + self.send_response(200, "OK") + self.end_headers() + self.wfile.write(request) + else: + self.send_response(400, "Empty request data") + self.end_headers() # Proxy test infrastructure @@ -314,6 +334,19 @@ def test_basic_auth_httperror(self): urllib.request.install_opener(urllib.request.build_opener(ah)) self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, self.server_url) + def test_basic_auth_mmap_payload(self): + from mmap import mmap + data = "field=value".encode("ascii") + mem = mmap(-1, len(data)) + mem[:] = data + auth_handler = urllib.request.HTTPBasicAuthHandler() + auth_handler.add_password(realm=self.REALM, uri=self.server_url, + user=self.USER, passwd=self.PASSWD) + opener = urllib.request.build_opener(auth_handler) + urllib.request.install_opener(opener) + response = opener.open(self.server_url, mem) + self.assertEqual(response.read(), data) + class ProxyAuthTests(unittest.TestCase): URL = "http://localhost" @@ -658,7 +691,6 @@ def test_line_iteration(self): (index, len(lines[index]), len(line))) self.assertEqual(index + 1, len(lines)) - threads_key = None def setUpModule(): From 87656e1fccabc4f1f651f3b6b195d15cb6e613d4 Mon Sep 17 00:00:00 2001 From: wiz-1 Date: Sat, 16 Feb 2019 02:57:33 +0700 Subject: [PATCH 4/4] add testcase, modify --- Lib/test/test_urllib2_localnet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index 3ca3f8be29e40b..4f767ed9555c46 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -259,6 +259,8 @@ def do_POST(self): else: self.send_response(400, "Empty request data") self.end_headers() + else: + self.do_AUTHHEAD() # Proxy test infrastructure pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy