Skip to content
Myr

redirect fix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent b4a4f38 · Browse files · 2 files+17 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−4 removed

  • other:+17 added−4 removed

2 files+17 added−4 removed

modified:requests/models.py+17 added-3 removed
4 unmodified lines
5~~~~~~~~~~~~~~~67"""89import requests9import urllib10import urllib211import socket12import zlib1314from urllib2 import HTTPError15from urlparse import urlparse16from datetime import datetime1718from .config import settings19from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler20from .structures import CaseInsensitiveDict21from .packages.poster.encode import multipart_encode22from .packages.poster.streaminghttp import register_openers, get_handlers23from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod242526REDIRECT_STATI = (301, 302, 303, 307)272829class Request(object):30 """The :class:`Request <models.Request>` object. It carries out all functionality of31 Requests. Recommended interface is with the Requests functions.32 """
138 unmodified lines
171 history = []172173 r = build(resp)174175 if r.status_code in REDIRECT_STATI:176 self.redirect = True177178 if self.redirect:179180 while (181 ('location' in r.headers) and
5 unmodified lines
187 history.append(r)188189 url = r.headers['location']190185 # Facilitate for non-RFC2616-compliant 'location' headers191 # Facilitate non-RFC2616-compliant 'location' headers192 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')193 if not urlparse(url).netloc:194 parent_url_components = urlparse(self.url)195 url = '%s://%s/%s' % (parent_url_components.scheme, parent_url_components.netloc, url)
6 unmodified lines
202203 request = Request(204 url, self.headers, self.files, method,205 self.data, self.params, self.auth, self.cookiejar,200 redirect=False206 redirect=True207 )208 request.send()209 r = request.response210
48 unmodified lines
259 """260 self._checks()261 success = False262263 # Logging264 if settings.verbose:265 settings.verbose.write('%s %s %s\n' % (266 datetime.now().isoformat(), self.method, self.url267 ))268269270 url = self._build_url()271 if self.method in ('GET', 'HEAD', 'DELETE'):272 req = _Request(url, method=self.method)273 else:
40 unmodified lines
314 self.response.cached = True315316 self.sent = self.response.ok317318319 return self.sent320321322 def read(self, *args):
226 unmodified lines
modified:requests/monkeys.py-1 removed
24 unmodified lines
25 return self.method2627 return urllib2.Request.get_method(self)282929class HTTPRedirectHandler(urllib2.HTTPRedirectHandler):3031 def http_error_301(self, req, fp, code, msg, headers):32 pass
58 unmodified lines