Commit 48257913 authored by Łukasz Nowak's avatar Łukasz Nowak

http: handle ContentDecodingError

parent 0a622d3f
...@@ -77,6 +77,7 @@ def request(url, timeout=TIMEOUT, headers=None, session=requests, version=0): ...@@ -77,6 +77,7 @@ def request(url, timeout=TIMEOUT, headers=None, session=requests, version=0):
except ( except (
requests.exceptions.Timeout, requests.exceptions.Timeout,
requests.exceptions.ChunkedEncodingError, requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError,
): ):
response = requests.models.Response() response = requests.models.Response()
response.status_code = 524 response.status_code = 524
......
...@@ -165,6 +165,19 @@ class SurykatkaHttpTestCase(unittest.TestCase): ...@@ -165,6 +165,19 @@ class SurykatkaHttpTestCase(unittest.TestCase):
assert mock_request.call_count == 1 assert mock_request.call_count == 1
assert response.status_code == 524, response.status_code assert response.status_code == 524, response.status_code
def test_request_ContentDecodingError(self):
url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy)
with mock.patch("surykatka.http.requests.request") as mock_request:
def sideEffect(*args, **kw):
raise surykatka.http.requests.exceptions.ContentDecodingError()
mock_request.side_effect = sideEffect
response = request(url_to_proxy)
assert mock_request.call_count == 1
assert response.status_code == 524, response.status_code
def test_request_tooManyRedirect(self): def test_request_tooManyRedirect(self):
url_to_proxy = "http://example.org/" url_to_proxy = "http://example.org/"
httpretty.register_uri(httpretty.GET, url_to_proxy) httpretty.register_uri(httpretty.GET, url_to_proxy)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment