Skip to content

Commit 2422b68

Browse files
authored
Fix chalice did not send content type headers (#3904)
* Fix Chalice did not send content-type headers * Add release file
1 parent 958c42d commit 2422b68

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Release type: patch
2+
3+
This release fixes that the Chalice HTTP view integration did not set
4+
appropriate content-type headers for responses, as it's recommended by the
5+
GraphQL over HTTP specification.

strawberry/chalice/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ def create_response(
124124
return Response(
125125
body=self.encode_json(response_data),
126126
status_code=status_code,
127-
headers=sub_response.headers, # type: ignore[arg-type]
127+
headers={
128+
"Content-Type": "application/json",
129+
**sub_response.headers,
130+
},
128131
)
129132

130133
def execute_request(self, request: Request) -> Response:

tests/http/test_graphql_over_http_spec.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ async def test_22eb(http_client):
2929
"""
3030
SHOULD accept application/graphql-response+json and match the content-type
3131
"""
32-
if isinstance(http_client, ChaliceHttpClient):
33-
pytest.xfail("The Chalice test client does not return any response headers")
34-
3532
response = await http_client.query(
3633
method="post",
3734
headers={
@@ -48,9 +45,6 @@ async def test_4655(http_client):
4845
"""
4946
MUST accept application/json and match the content-type
5047
"""
51-
if isinstance(http_client, ChaliceHttpClient):
52-
pytest.xfail("The Chalice test client does not return any response headers")
53-
5448
response = await http_client.query(
5549
method="post",
5650
headers={
@@ -67,9 +61,6 @@ async def test_47de(http_client):
6761
"""
6862
SHOULD accept */* and use application/json for the content-type
6963
"""
70-
if isinstance(http_client, ChaliceHttpClient):
71-
pytest.xfail("The Chalice test client does not return any response headers")
72-
7364
response = await http_client.query(
7465
method="post",
7566
headers={
@@ -86,9 +77,6 @@ async def test_80d8(http_client):
8677
"""
8778
SHOULD assume application/json content-type when accept is missing
8879
"""
89-
if isinstance(http_client, ChaliceHttpClient):
90-
pytest.xfail("The Chalice test client does not return any response headers")
91-
9280
response = await http_client.query(
9381
method="post",
9482
headers={"Content-Type": "application/json"},

0 commit comments

Comments
 (0)