cpython: 841a9a3f3cf6 (original) (raw)

Mercurial > cpython

changeset 101372:841a9a3f3cf6

Issue #14132, Issue #17214: Merge two redirect handling fixes from 3.5 [#14132]

Martin Panter vadmium+py@gmail.com
date Mon, 16 May 2016 07:45:28 +0000
parents 8c973a2f4f50(current diff)cb09fdef19f5(diff)
children 0fe913de4702
files Lib/test/test_urllib2.py Lib/urllib/request.py Misc/NEWS
diffstat 4 files changed, 76 insertions(+), 5 deletions(-)[+] [-] Lib/test/test_urllib.py 7 Lib/test/test_urllib2.py 51 Lib/urllib/request.py 14 Misc/NEWS 9

line wrap: on

line diff

--- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -1,4 +1,4 @@ -"""Regresssion tests for urllib""" +"""Regresssion tests for what was in Python 2's "urllib" module""" import urllib.parse import urllib.request @@ -86,10 +86,11 @@ def fakehttp(fakedata): # buffer to store data for verification in urlopen tests. buf = None

def connect(self):

return FakeHTTPConnection

--- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1208,6 +1208,57 @@ class HandlerTests(unittest.TestCase): fp = o.open('http://www.example.com')[](#l2.4) self.assertEqual(fp.geturl(), redirected_url.strip())

+

+ def test_proxy(self): o = OpenerDirector() ph = urllib.request.ProxyHandler(dict(http="proxy.example.com:3128"))

--- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -91,6 +91,7 @@ import os import posixpath import re import socket +import string import sys import time import collections @@ -676,8 +677,12 @@ class HTTPRedirectHandler(BaseHandler): # from the user (of urllib.request, in this case). In practice, # essentially all clients do redirect in this case, so we do # the same.

+

+ CONTENT_HEADERS = ("content-length", "content-type") newheaders = dict((k, v) for k, v in req.headers.items() if k.lower() not in CONTENT_HEADERS) @@ -712,11 +717,16 @@ class HTTPRedirectHandler(BaseHandler): "%s - Redirection to url '%s' is not allowed" % (msg, newurl), headers, fp)

# XXX Probably want to forget about the state of the current

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -277,6 +277,15 @@ Core and Builtins Library ------- +- Issue #14132: Fix urllib.request redirect handling when the target only has