diff --git a/bravado/http_future.py b/bravado/http_future.py index 8bfa65d7..3ab9eb7b 100644 --- a/bravado/http_future.py +++ b/bravado/http_future.py @@ -389,6 +389,9 @@ def unmarshal_response_inner( value=content_value, ) + if content_type.startswith('application'): + return response.raw_bytes + # TODO: Non-json response contents return response.text diff --git a/tests/http_future/unmarshall_response_inner_test.py b/tests/http_future/unmarshall_response_inner_test.py index 230989c3..b2a37240 100644 --- a/tests/http_future/unmarshall_response_inner_test.py +++ b/tests/http_future/unmarshall_response_inner_test.py @@ -89,6 +89,20 @@ def test_text_content(mock_get_response_spec, empty_swagger_spec, response_spec) assert 'Monday' == unmarshal_response_inner(response, op) +def test_binary_content(mock_get_response_spec, empty_swagger_spec, response_spec): + response = mock.Mock( + spec=IncomingResponse, + status_code=200, + headers={'content-type': 'application/octet-stream'}, + text='Monday', + raw_bytes='SomeBinaryData' + ) + + mock_get_response_spec.return_value = response_spec + op = mock.Mock(swagger_spec=empty_swagger_spec) + assert 'SomeBinaryData' == unmarshal_response_inner(response, op) + + def test_skips_validation(mock_validate_schema_object, mock_get_response_spec, empty_swagger_spec, response_spec): empty_swagger_spec.config['validate_responses'] = False response = mock.Mock(