Merge remote-tracking branch 'origin/master'

This commit is contained in:
Kenneth Reitz
2014-05-16 13:44:21 -04:00
5 changed files with 65 additions and 11 deletions
+14 -1
View File
@@ -3,7 +3,7 @@
Release History
---------------
X.X.X (YYYY-MM-DD)
2.3.0 (2014-05-12)
++++++++++++++++++
**API Changes**
@@ -13,11 +13,24 @@ X.X.X (YYYY-MM-DD)
or not it actually did).
- The ``timeout`` parameter now affects requests with both ``stream=True`` and
``stream=False`` equally.
- The change in v2.0.0 to mandate explicit proxy schemes has been reverted.
Proxy schemes now default to ``http://``.
- The ``CaseInsensitiveDict`` used for HTTP headers now behaves like a normal
dictionary when printed as a string or in the interpreter.
**Bugfixes**
- No longer expose Authorization or Proxy-Authorization headers on redirect.
Fix CVE-2014-1829 and CVE-2014-1830 respectively.
- Authorization is re-evaluated each redirect.
- On redirect, pass url as native strings.
- Fall-back to autodetected encoding for JSON when Unicode detection fails.
- Headers set to ``None`` on the ``Session`` are now correctly not sent.
- Correctly honor ``decode_unicode`` even if it wasn't used earlier in the same
response.
- Stop advertising ``compress`` as a supported Content-Encoding.
- The ``Response.history`` parameter is now always a list.
- Many, many ``urllib3`` bugfixes.
2.2.1 (2014-01-23)
++++++++++++++++++
+1 -1
View File
@@ -111,7 +111,7 @@ request. The simple recipe for this is the following::
Since you are not doing anything special with the ``Request`` object, you
prepare it immediately and modify the ``PreparedRequest`` object. You then
send that with the other parameters you would have sent to ``requests.*`` or
``Sesssion.*``.
``Session.*``.
However, the above code will lose some of the advantages of having a Requests
:class:`Session <requests.Session>` object. In particular,
+1 -6
View File
@@ -385,9 +385,4 @@ class HTTPAdapter(BaseAdapter):
else:
raise
r = self.build_response(request, resp)
if not stream:
r.content
return r
return self.build_response(request, resp)
+9 -2
View File
@@ -19,7 +19,8 @@ from .cookies import (
from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT
from .hooks import default_hooks, dispatch_hook
from .utils import to_key_val_list, default_headers, to_native_string
from .exceptions import TooManyRedirects, InvalidSchema
from .exceptions import (
TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError)
from .structures import CaseInsensitiveDict
from .adapters import HTTPAdapter
@@ -94,7 +95,10 @@ class SessionRedirectMixin(object):
while resp.is_redirect:
prepared_request = req.copy()
resp.content # Consume socket so it can be released
try:
resp.content # Consume socket so it can be released
except (ChunkedEncodingError, ContentDecodingError, RuntimeError):
resp.raw.read(decode_content=False)
if i >= self.max_redirects:
raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects)
@@ -588,6 +592,9 @@ class Session(SessionRedirectMixin):
r = history.pop()
r.history = history
if not stream:
r.content
return r
def get_adapter(self, url):
+40 -1
View File
@@ -917,6 +917,45 @@ class RequestsTestCase(unittest.TestCase):
assert h1 == h2
def test_manual_redirect_with_partial_body_read(self):
s = requests.Session()
r1 = s.get(httpbin('redirect/2'), allow_redirects=False, stream=True)
assert r1.is_redirect
rg = s.resolve_redirects(r1, r1.request, stream=True)
# read only the first eight bytes of the response body,
# then follow the redirect
r1.iter_content(8)
r2 = next(rg)
assert r2.is_redirect
# read all of the response via iter_content,
# then follow the redirect
for _ in r2.iter_content():
pass
r3 = next(rg)
assert not r3.is_redirect
def _patch_adapter_gzipped_redirect(self, session, url):
adapter = session.get_adapter(url=url)
org_build_response = adapter.build_response
self._patched_response = False
def build_response(*args, **kwargs):
resp = org_build_response(*args, **kwargs)
if not self._patched_response:
resp.raw.headers['content-encoding'] = 'gzip'
self._patched_response = True
return resp
adapter.build_response = build_response
def test_redirect_with_wrong_gzipped_header(self):
s = requests.Session()
url = httpbin('redirect/1')
self._patch_adapter_gzipped_redirect(s, url)
s.get(url)
class TestContentEncodingDetection(unittest.TestCase):
@@ -1321,7 +1360,7 @@ def test_data_argument_accepts_tuples(list_of_tuples):
hooks=default_hooks()
)
assert p.body == urlencode(data)
if __name__ == '__main__':
unittest.main()