Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3801174

Browse files
committed
Patch for an Issue #1157
1 parent 66c2a79 commit 3801174

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/request/connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _connReadProxy(conn):
166166

167167
if not kb.dnsMode and conn:
168168
headers = conn.info()
169-
if headers and (headers.getheader(HTTP_HEADER.CONTENT_ENCODING, "").lower() in ("gzip", "deflate")\
169+
if headers and hasattr(headers, "getheader") and (headers.getheader(HTTP_HEADER.CONTENT_ENCODING, "").lower() in ("gzip", "deflate")\
170170
or "text" not in headers.getheader(HTTP_HEADER.CONTENT_TYPE, "").lower()):
171171
retVal = conn.read(MAX_CONNECTION_TOTAL_SIZE)
172172
if len(retVal) == MAX_CONNECTION_TOTAL_SIZE:

lib/request/redirecthandler.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8+
import types
89
import urllib2
910
import urlparse
1011

@@ -124,6 +125,25 @@ def http_error_302(self, req, fp, code, msg, headers):
124125
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
125126
except urllib2.HTTPError, e:
126127
result = e
128+
129+
# Dirty hack for http://bugs.python.org/issue15701
130+
try:
131+
result.info()
132+
except AttributeError:
133+
def _(self):
134+
return getattr(self, "hdrs") or {}
135+
result.info = types.MethodType(_, result)
136+
137+
if not hasattr(result, "read"):
138+
def _(self, length=None):
139+
return e.msg
140+
result.read = types.MethodType(_, result)
141+
142+
if not getattr(result, "url", None):
143+
result.url = redurl
144+
145+
if not getattr(result, "code", None):
146+
result.code = 999
127147
except:
128148
redurl = None
129149
result = fp

0 commit comments

Comments
 (0)