diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..3bcb465b22 --- /dev/null +++ b/RELEASE.md @@ -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. diff --git a/strawberry/http/async_base_view.py b/strawberry/http/async_base_view.py index a9997bcc7f..7eef89aa40 100644 --- a/strawberry/http/async_base_view.py +++ b/strawberry/http/async_base_view.py @@ -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") diff --git a/tests/http/test_multipart_subscription.py b/tests/http/test_multipart_subscription.py index 9f6f5f18a7..98379949ee 100644 --- a/tests/http/test_multipart_subscription.py +++ b/tests/http/test_multipart_subscription.py @@ -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", }, )