Skip to content
Myr

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

5 files+65 added−11 removed

modified:docs/user/advanced.rst+1 added-1 removed
109 unmodified lines
110111Since you are not doing anything special with the ``Request`` object, you112prepare it immediately and modify the ``PreparedRequest`` object. You then113send that with the other parameters you would have sent to ``requests.*`` or114``Sesssion.*``.114``Session.*``.115116However, 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 will
564 unmodified lines
modified:requests/adapters.py+1 added-6 removed
383 unmodified lines
384 raise Timeout(e, request=request)385 else:386 raise387388 r = self.build_response(request, resp)389390 if not stream:391 r.content392393 return r388 return self.build_response(request, resp)
modified:requests/sessions.py+9 added-2 removed
17 unmodified lines
18 cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)19from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT20from .hooks import default_hooks, dispatch_hook21from .utils import to_key_val_list, default_headers, to_native_string22from .exceptions import TooManyRedirects, InvalidSchema22from .exceptions import (23 TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError)24from .structures import CaseInsensitiveDict2526from .adapters import HTTPAdapter27
66 unmodified lines
9495 while resp.is_redirect:96 prepared_request = req.copy()9798 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)102103 if i >= self.max_redirects:104 raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects)105
485 unmodified lines
591 # Get the last request made592 r = history.pop()593 r.history = history594595 if not stream:596 r.content597598 return r599600 def get_adapter(self, url):601 """Returns the appropriate connnection adapter for the given URL."""
36 unmodified lines
modified:HISTORY.rst+14 added-1 removed
1 unmodified line
23Release History4---------------56X.X.X (YYYY-MM-DD)62.3.0 (2014-05-12)7++++++++++++++++++89**API Changes**10
1 unmodified line
12 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.2021**Bugfixes**2223- 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.34352.2.1 (2014-01-23)36++++++++++++++++++37
763 unmodified lines
modified:test_requests.py+40 added-1 removed
915 unmodified lines
916 h2 = r.request.headers['Authorization']917918 assert h1 == h2919920 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)925926 # 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_redirect931932 # 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_redirect938939 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 = False943944 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 resp950951 adapter.build_response = build_response952953 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)958959960class TestContentEncodingDetection(unittest.TestCase):961962 def test_none(self):963 encodings = requests.utils.get_encodings_from_content('')
395 unmodified lines
1359 data=data,1360 hooks=default_hooks()1361 )1362 assert p.body == urlencode(data)1324 136313641365if __name__ == '__main__':1366 unittest.main()