Merge remote-tracking branch 'origin/master'
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 · parents c15a8f8, bbed65d · Browse files · 5 files·+65 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+65 added−11 removed
- other:+65 added−11 removed
Provenance
- Commit
343db40- Tree
0df3486- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
c15a8f8- Parent 2
bbed65d
5 files changed+65 added−11 removed
modified:docs/user/advanced.rst+1 added-1 removed
109 unmodified lines110 111 Since you are not doing anything special with the ``Request`` object, you112 prepare it immediately and modify the ``PreparedRequest`` object. You then113 send that with the other parameters you would have sent to ``requests.*`` or114-``Sesssion.*``.114+``Session.*``.115 116 However, the above code will lose some of the advantages of having a Requests117 :class:`Session <requests.Session>` object. In particular,118 :class:`Session <requests.Session>`-level state such as cookies will564 unmodified linesmodified:requests/adapters.py+1 added-6 removed
383 unmodified lines384 raise Timeout(e, request=request)385 else:386 raise387 388- r = self.build_response(request, resp)389-390- if not stream:391- r.content392-393- return r388+ return self.build_response(request, resp)modified:requests/sessions.py+9 added-2 removed
17 unmodified lines18 cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)19 from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT20 from .hooks import default_hooks, dispatch_hook21 from .utils import to_key_val_list, default_headers, to_native_string22-from .exceptions import TooManyRedirects, InvalidSchema22+from .exceptions import (23+ TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError)24 from .structures import CaseInsensitiveDict25 26 from .adapters import HTTPAdapter27 66 unmodified lines94 95 while resp.is_redirect:96 prepared_request = req.copy()97 98+ try:97- resp.content # Consume socket so it can be released99+ resp.content # Consume socket so it can be released100+ except (ChunkedEncodingError, ContentDecodingError, RuntimeError):101+ resp.raw.read(decode_content=False)102 103 if i >= self.max_redirects:104 raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects)105 485 unmodified lines591 # Get the last request made592 r = history.pop()593 r.history = history594 595+ if not stream:596+ r.content597+598 return r599 600 def get_adapter(self, url):601 """Returns the appropriate connnection adapter for the given URL."""36 unmodified linesmodified:HISTORY.rst+14 added-1 removed
1 unmodified line2 3 Release History4 ---------------5 6-X.X.X (YYYY-MM-DD)6+2.3.0 (2014-05-12)7 ++++++++++++++++++8 9 **API Changes**10 1 unmodified line12 library could have processed this response as a redirection (whether13 or not it actually did).14 - The ``timeout`` parameter now affects requests with both ``stream=True`` and15 ``stream=False`` equally.16+- The change in v2.0.0 to mandate explicit proxy schemes has been reverted.17+ Proxy schemes now default to ``http://``.18+- The ``CaseInsensitiveDict`` used for HTTP headers now behaves like a normal19+ dictionary when printed as a string or in the interpreter.20 21 **Bugfixes**22 23 - No longer expose Authorization or Proxy-Authorization headers on redirect.24 Fix CVE-2014-1829 and CVE-2014-1830 respectively.25+- Authorization is re-evaluated each redirect.26+- On redirect, pass url as native strings.27+- Fall-back to autodetected encoding for JSON when Unicode detection fails.28+- Headers set to ``None`` on the ``Session`` are now correctly not sent.29+- Correctly honor ``decode_unicode`` even if it wasn't used earlier in the same30+ response.31+- Stop advertising ``compress`` as a supported Content-Encoding.32+- The ``Response.history`` parameter is now always a list.33+- Many, many ``urllib3`` bugfixes.34 35 2.2.1 (2014-01-23)36 ++++++++++++++++++37 763 unmodified linesmodified:test_requests.py+40 added-1 removed
915 unmodified lines916 h2 = r.request.headers['Authorization']917 918 assert h1 == h2919 920+ def test_manual_redirect_with_partial_body_read(self):921+ s = requests.Session()922+ r1 = s.get(httpbin('redirect/2'), allow_redirects=False, stream=True)923+ assert r1.is_redirect924+ rg = s.resolve_redirects(r1, r1.request, stream=True)925 926+ # read only the first eight bytes of the response body,927+ # then follow the redirect928+ r1.iter_content(8)929+ r2 = next(rg)930+ assert r2.is_redirect931+932+ # read all of the response via iter_content,933+ # then follow the redirect934+ for _ in r2.iter_content():935+ pass936+ r3 = next(rg)937+ assert not r3.is_redirect938+939+ def _patch_adapter_gzipped_redirect(self, session, url):940+ adapter = session.get_adapter(url=url)941+ org_build_response = adapter.build_response942+ self._patched_response = False943+944+ def build_response(*args, **kwargs):945+ resp = org_build_response(*args, **kwargs)946+ if not self._patched_response:947+ resp.raw.headers['content-encoding'] = 'gzip'948+ self._patched_response = True949+ return resp950+951+ adapter.build_response = build_response952+953+ def test_redirect_with_wrong_gzipped_header(self):954+ s = requests.Session()955+ url = httpbin('redirect/1')956+ self._patch_adapter_gzipped_redirect(s, url)957+ s.get(url)958+959+960 class TestContentEncodingDetection(unittest.TestCase):961 962 def test_none(self):963 encodings = requests.utils.get_encodings_from_content('')395 unmodified lines1359 data=data,1360 hooks=default_hooks()1361 )1362 assert p.body == urlencode(data)1324- 1363 1364+1365 if __name__ == '__main__':1366 unittest.main()