Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions connexion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,8 @@ def extract_content_type(

if decoded_key.lower() == "content-type":
if isinstance(value, bytes):
content_type = value.decode("latin-1")
else:
content_type = value
break
value = value.decode("latin-1")
content_type = ",".join([content_type, value] if content_type else [value])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be only one content-type header. If there are multiple, I believe it is more appropriate to raise a BadRequest error to return a 400 status code


return content_type

Expand Down
23 changes: 23 additions & 0 deletions tests/test_json_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,26 @@ class MyDefaultsJSONBodyValidator(DefaultsJSONRequestBodyValidator):
)
assert res.status_code == 200
assert res.json().get("human")


def test_multiple_json_content_type(json_validation_spec_dir, spec):
"""ensure that defaults applied that modify the body"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring is the one from the test above, it should be about multiple content type headers?


class MyDefaultsJSONBodyValidator(DefaultsJSONRequestBodyValidator):
pass

validator_map = {"body": {"application/json": MyDefaultsJSONBodyValidator}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to update the custom body validator in this test


app = App(__name__, specification_dir=json_validation_spec_dir)
app.add_api(spec, validate_responses=True, validator_map=validator_map)
app_client = app.test_client()

res = app_client.post(
"/v1.0/user",
data=json.dumps({"name": "foo"}),
headers={
"content-type": "application/json",
"Content-Type": "application/json",
},
)
assert res.status_code == 415