Skip to content

bpo-5038: http lib, seek to the beginning of mmap'ed file #11843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 36 additions & 2 deletions Lib/test/test_urllib2_localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,29 @@ 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()
else:
self.do_AUTHHEAD()

# Proxy test infrastructure

Expand Down Expand Up @@ -314,6 +336,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"
Expand Down Expand Up @@ -658,7 +693,6 @@ def test_line_iteration(self):
(index, len(lines[index]), len(line)))
self.assertEqual(index + 1, len(lines))


threads_key = None

def setUpModule():
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
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