Skip to content

Commit

Permalink
Merge pull request #382 from patrickw276/content-type
Browse files Browse the repository at this point in the history
fix content-type header bug
  • Loading branch information
rafaelcaricio committed Jan 10, 2017
2 parents a6fbeb8 + 576275e commit 34ec0ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions connexion/decorators/decorator.py
Expand Up @@ -174,8 +174,8 @@ def flask_response_object(self):
:rtype: flask.Response
"""
self._response = flask.current_app.response_class(
self.data, mimetype=self.mimetype) # type: flask.Response
self.data, mimetype=self.mimetype, content_type=self.headers.get('content-type'),
headers=self.headers) # type: flask.Response
self._response.status_code = self.status_code
self._response.headers.extend(self.headers)

return self._response
15 changes: 15 additions & 0 deletions tests/decorators/test_decorators.py
@@ -0,0 +1,15 @@
import flask
from connexion.decorators.decorator import ResponseContainer


def test_response_container_content_type():
app = flask.Flask(__name__)
response = flask.Response(response='test response', content_type='text/plain')
container = ResponseContainer(mimetype='application/json', response=response)

with app.app_context():
headers = container.flask_response_object().headers

content_types = [value for key, value in headers.items() if key == 'Content-Type']
assert len(content_types) == 1
assert content_types[0] == 'text/plain'
2 changes: 1 addition & 1 deletion tests/test_validation.py
Expand Up @@ -12,7 +12,7 @@ def test_parameter_validator(monkeypatch):
request.params = {}
app = MagicMock(name='app')

def _response_class(data, mimetype):
def _response_class(data, mimetype, content_type, headers):
response = MagicMock(name='response')
response.detail = json.loads(''.join(data))['detail']
response.headers = MagicMock()
Expand Down

0 comments on commit 34ec0ec

Please sign in to comment.