mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add correct defaults in Session.send()
Resolves #1258 Also fixed the tests to reflect the necessary changes.
This commit is contained in:
@@ -316,7 +316,6 @@ class Session(SessionRedirectMixin):
|
||||
'cert': cert,
|
||||
'proxies': proxies,
|
||||
'allow_redirects': allow_redirects,
|
||||
'req': req,
|
||||
}
|
||||
resp = self.send(prep, **send_kwargs)
|
||||
|
||||
@@ -398,14 +397,17 @@ class Session(SessionRedirectMixin):
|
||||
"""Send a given PreparedRequest."""
|
||||
# It's possible that users might accidentally send a Request object.
|
||||
# Guard against that specific failure case.
|
||||
kwargs.setdefault('stream', False)
|
||||
kwargs.setdefault('verify', True)
|
||||
kwargs.setdefault('proxies', {})
|
||||
|
||||
if getattr(request, 'prepare', None):
|
||||
raise ValueError('You can only send PreparedRequests.')
|
||||
|
||||
# Set up variables needed for resolve_redirects and dispatching of
|
||||
# hooks
|
||||
allow_redirects = kwargs.pop('allow_redirects', True)
|
||||
req = kwargs.pop('req', None)
|
||||
stream = kwargs.get('stream', False)
|
||||
stream = kwargs.get('stream')
|
||||
timeout = kwargs.get('timeout')
|
||||
verify = kwargs.get('verify')
|
||||
cert = kwargs.get('cert')
|
||||
|
||||
+8
-1
@@ -295,8 +295,15 @@ class RequestsTestCase(unittest.TestCase):
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertTrue(b"text/py-content-type" in r.request.body)
|
||||
|
||||
def test_hook_receives_request_arguments(self):
|
||||
def hook(resp, **kwargs):
|
||||
assert resp is not None
|
||||
assert kwargs != {}
|
||||
|
||||
requests.Request('GET', HTTPBIN, hooks={'response': hook})
|
||||
|
||||
def test_prepared_request_hook(self):
|
||||
def hook(resp):
|
||||
def hook(resp, **kwargs):
|
||||
resp.hook_working = True
|
||||
return resp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user