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
Provenance
- Commit
b4eac4c- Tree
4bbe5c2- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
b4a4f38
2 files changed+17 added−4 removed
modified:requests/models.py+17 added-3 removed
4 unmodified lines5 ~~~~~~~~~~~~~~~6 7 """8 9-import requests9 import urllib10 import urllib211 import socket12 import zlib13 14 from urllib2 import HTTPError15 from urlparse import urlparse16+from datetime import datetime17 18+from .config import settings19 from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler20 from .structures import CaseInsensitiveDict21 from .packages.poster.encode import multipart_encode22 from .packages.poster.streaminghttp import register_openers, get_handlers23 from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod24 25 26+REDIRECT_STATI = (301, 302, 303, 307)27 28+29 class 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 lines171 history = []172 173 r = build(resp)174 175+ if r.status_code in REDIRECT_STATI:176+ self.redirect = True177+178 if self.redirect:179 180 while (181 ('location' in r.headers) and5 unmodified lines187 history.append(r)188 189 url = r.headers['location']190 185- # 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 lines202 203 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 lines259 """260 self._checks()261 success = False262 263+ # Logging264+ if settings.verbose:265+ settings.verbose.write('%s %s %s\n' % (266+ datetime.now().isoformat(), self.method, self.url267+ ))268+269+270 url = self._build_url()271 if self.method in ('GET', 'HEAD', 'DELETE'):272 req = _Request(url, method=self.method)273 else:40 unmodified lines314 self.response.cached = True315 316 self.sent = self.response.ok317 318+319 return self.sent320 321 322 def read(self, *args):226 unmodified linesmodified:requests/monkeys.py-1 removed
24 unmodified lines25 return self.method26 27 return urllib2.Request.get_method(self)28 29-29 class HTTPRedirectHandler(urllib2.HTTPRedirectHandler):30 31 def http_error_301(self, req, fp, code, msg, headers):32 pass58 unmodified lines