Skip to content
Myr

Merge pull request #764 from slingamn/regressions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

test and fix regressions from #760

authored by Kenneth Reitz · committed by Kenneth Reitz · parents a94fcb8, 291859c · Browse files · 2 files+25 added−3 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+25 added−3 removed

  • tests:+16 added−0 removed
  • other:+9 added−3 removed

2 files+25 added−3 removed

modified:requests/models.py+9 added-3 removed
289 unmodified lines
290 _poolmanager=self._poolmanager,291 proxies=self.proxies,292 verify=self.verify,293 session=self.session,294 cert=self.cert294 cert=self.cert,295 prefetch=self.prefetch,296 )297298 request.send()299 r = request.response
158 unmodified lines
458 return True459 except ValueError:460 return False461461 def send(self, anyway=False, prefetch=True):462 def send(self, anyway=False, prefetch=None):463 """Sends the request. Returns True if successful, False if not.464 If there was an HTTPError during transmission,465 self.response.status_code will contain the HTTPError code.466467 Once a request is successfully sent, `sent` will equal True.468469 :param anyway: If True, request will be sent, even if it has470 already been sent.471472 :param prefetch: If not None, will override the request's own setting473 for prefetch.474 """475476 # Build the URL477 url = self.full_url
151 unmodified lines
629 r = dispatch_hook('post_request', self.hooks, self)630 self.__dict__.update(r.__dict__)631632 # If prefetch is True, mark content as consumed.629 if prefetch or self.prefetch:633 if prefetch is None:634 prefetch = self.prefetch635 if prefetch:636 # Save the response.637 self.response.content638639 if self.config.get('danger_mode'):
212 unmodified lines
modified:tests/test_requests.py+16 added
977 unmodified lines
978 r = post(httpbin('post'), data=data)979 t = json.loads(r.text)980 self.assertEqual(t.get('headers').get('Content-Type'), '')981982 def test_prefetch_redirect_bug(self):983 """Test that prefetch persists across redirections."""984 res = get(httpbin('redirect/2'), prefetch=False)985 # prefetch should persist across the redirect; if it doesn't,986 # this attempt to iterate will crash because the content has already987 # been read.988 first_line = next(res.iter_lines())989 self.assertTrue(first_line.strip().decode('utf-8').startswith('{'))990991 def test_prefetch_return_response_interaction(self):992 """Test that prefetch can be overridden as a kwarg to `send`."""993 req = requests.get(httpbin('get'), return_response=False)994 req.send(prefetch=False)995 # content should not have been prefetched, and iter_lines should succeed996 first_line = next(req.response.iter_lines())997 self.assertTrue(first_line.strip().decode('utf-8').startswith('{'))998999if __name__ == '__main__':1000 unittest.main()