ChilliCream / ChilliCream/graphql-platform
Add "X-Accel-Buffering: no" header to improve subscriptions with reverse proxy
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Product
Hot Chocolate
Is your feature request related to a problem?
I've personally encountered this issue but I also saw others are experiencing it so I'm opening an issue.
The issue is that when you use Server-Sent Events in Subscriptions in Hot Chocolate and your server is running behind a reverse proxy such as Azure Application Gateway that uses response buffering, you either never receive subscription events or the events are delayed. The reason for this is because Hot Chocolate's endpoints don't add a specific header: X-Accel-Buffering set to no, which configures the reverse proxy to send data as its received rather than waiting for the entire (potentially endless) response.
I figured this out based off of this StackOverflow question but there isn't a lot of information about it that I've been able to find.
The solution you'd like
The solution I used to fix this problem was to add a middleware to detect whether we're serving GraphQL requests and to add this header:
app.Use((ctx, next) => {
if (ctx.Request.Path.ToString().Contains("/graphql")) {
var headers = ctx.Response.Headers;
headers.Append("X-Accel-Buffering", "no");
}
return next();
});
This works, but I had to do it this way because I couldn't find a way to configure the headers that Hot Chocolate sends to include the header. It'd be advantageous if this was an option built into Hot Chocolate and documented so that anyone else using a setup like this can benefit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Hot Chocolate's GraphQL endpoint handling and Server-Sent Events subscription response path, then check how response headers are configured. Determine where an opt-in or automatic X-Accel-Buffering: no header belongs, and identify the relevant subscription or endpoint tests. Done means reverse-proxy buffering is disabled for subscription responses and the configuration is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend-api-design, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100