Skip to content

Commit

Permalink
Check multipart subscriptions using accept header (#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 authored Sep 13, 2024
1 parent 08cc1c2 commit 7f84ed4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: patch

This release fixes how we check for multipart subscriptions to be
in line with the latest changes in the spec.
12 changes: 6 additions & 6 deletions strawberry/http/async_base_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,21 @@ async def parse_multipart_subscriptions(
async def parse_http_body(
self, request: AsyncHTTPRequestAdapter
) -> GraphQLRequestData:
content_type, params = parse_content_type(request.content_type or "")
headers = {key.lower(): value for key, value in request.headers.items()}
content_type, _ = parse_content_type(request.content_type or "")
accept = headers.get("accept", "")

protocol: Literal["http", "multipart-subscription"] = "http"

if self._is_multipart_subscriptions(*parse_content_type(accept)):
protocol = "multipart-subscription"

if request.method == "GET":
data = self.parse_query_params(request.query_params)
if self._is_multipart_subscriptions(content_type, params):
protocol = "multipart-subscription"
elif "application/json" in content_type:
data = self.parse_json(await request.get_body())
elif content_type == "multipart/form-data":
data = await self.parse_multipart(request)
elif self._is_multipart_subscriptions(content_type, params):
data = await self.parse_multipart_subscriptions(request)
protocol = "multipart-subscription"
else:
raise HTTPException(400, "Unsupported content type")

Expand Down
3 changes: 2 additions & 1 deletion tests/http/test_multipart_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async def test_multipart_subscription(
method=method,
query='subscription { echo(message: "Hello world", delay: 0.2) }',
headers={
"content-type": "multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json",
"accept": "multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json",
"content-type": "application/json",
},
)

Expand Down

0 comments on commit 7f84ed4

Please sign in to comment.