0004-utils-raise-on-HTTP-error-and-unwanted-redirects-311.patch
passerelle/utils/__init__.py | ||
---|---|---|
21 | 21 |
from itertools import islice, chain |
22 | 22 |
import warnings |
23 | 23 | |
24 |
from requests import Session as RequestSession, Response as RequestResponse |
|
24 |
from requests import Session as RequestSession, Response as RequestResponse, HTTPError
|
|
25 | 25 |
from requests.structures import CaseInsensitiveDict |
26 | 26 |
from urllib3.exceptions import InsecureRequestWarning |
27 | 27 | |
... | ... | |
191 | 191 |
def request(self, method, url, **kwargs): |
192 | 192 |
cache_duration = kwargs.pop('cache_duration', None) |
193 | 193 |
invalidate_cache = kwargs.pop('invalidate_cache', False) |
194 |
raise_for_status = kwargs.pop('raise_for_status', True) |
|
195 |
raise_for_redirect = kwargs.pop('raise_for_redirect', True) |
|
194 | 196 | |
195 | 197 |
if self.resource: |
196 | 198 |
if 'auth' not in kwargs: |
... | ... | |
236 | 238 |
warnings.simplefilter(action='ignore', category=InsecureRequestWarning) |
237 | 239 |
response = super(Request, self).request(method, url, **kwargs) |
238 | 240 | |
241 |
if raise_for_status: |
|
242 |
response.raise_for_status() |
|
243 | ||
244 |
if raise_for_redirect and response.status_code // 100 == 3: |
|
245 |
raise HTTPError('Unexpected redirect %s' % response.status_code, response=response) |
|
246 | ||
239 | 247 |
if method == 'GET' and cache_duration and (response.status_code // 100 == 2): |
240 | 248 |
cache.set(cache_key, { |
241 | 249 |
'content': response.content, |
242 |
- |