Skip to content

Skip multipart parts with empty Content-Type instead of raising#598

Open
magicmark wants to merge 2 commits into
graphql-python:masterfrom
magicmark:fix-empty-content-type-heartbeat
Open

Skip multipart parts with empty Content-Type instead of raising#598
magicmark wants to merge 2 commits into
graphql-python:masterfrom
magicmark:fix-empty-content-type-heartbeat

Conversation

@magicmark

@magicmark magicmark commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Multipart HTTP streams may contain empty parts (no headers, no body):

NO header fields are actually required in body parts. A body part that starts with a blank line, therefore, is allowed
~ https://www.rfc-editor.org/info/rfc2046/#section-5.1

(In our case, we see this (I think) due to being passed through multiple proxies which unpack and pack parts back together)

Anyway our current handling is too strict — it required every part to have Content-Type: application/json instead of just skipping empty ones.

Before

When this happens, applications see traceback like this:

gql.transport.exceptions.TransportProtocolError: Unexpected part content-type: . Expected 'application/json'.
Unexpected part content-type: . Expected 'application/json'.

After

✨ empty parts are ignored; no errors

@magicmark magicmark marked this pull request as ready for review June 30, 2026 05:51
@magicmark magicmark force-pushed the fix-empty-content-type-heartbeat branch from b6f13dc to 1ff86bc Compare June 30, 2026 05:58
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7fb869a) to head (2b12b85).
⚠️ Report is 69 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##            master      #598    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           38        40     +2     
  Lines         2908      3325   +417     
==========================================
+ Hits          2908      3325   +417     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Some GraphQL servers send multipart parts without a Content-Type
header as heartbeats or keep-alive padding. Previously this raised
a TransportProtocolError, crashing the subscription stream.

Co-Authored-By: Claude <noreply@anthropic.com>
@magicmark magicmark force-pushed the fix-empty-content-type-heartbeat branch from 1ff86bc to d0d2600 Compare June 30, 2026 06:02
@leszekhanusz

Copy link
Copy Markdown
Collaborator

According to the appolo graphql multipart documentation, an empty json object should be sent to specify a heartbeat: https://www.apollographql.com/docs/graphos/routing/operations/subscriptions/multipart-protocol#heartbeats

@leszekhanusz

Copy link
Copy Markdown
Collaborator

Please modify the code to only skip a part without content-type if it is empty.

@leszekhanusz

Copy link
Copy Markdown
Collaborator

And please don't force-push, all the commits will be squashed anyway when the PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants