Add X-Accel-Buffering header to SSE responses (#1294)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
parent
43a302ffa9
commit
2e17550303
3 changed files with 13 additions and 0 deletions
|
|
@ -339,6 +339,7 @@ internal sealed class StreamableHttpHandler(
|
|||
|
||||
// Make sure we disable all response buffering for SSE.
|
||||
context.Response.Headers.ContentEncoding = "identity";
|
||||
context.Response.Headers["X-Accel-Buffering"] = "no";
|
||||
context.Features.GetRequiredFeature<IHttpResponseBodyFeature>().DisableBuffering();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ public class SseServerIntegrationTests(SseServerIntegrationTestFixture fixture,
|
|||
Assert.NotNull(sseResponse.Headers.CacheControl);
|
||||
Assert.True(sseResponse.Headers.CacheControl.NoStore);
|
||||
Assert.True(sseResponse.Headers.CacheControl.NoCache);
|
||||
Assert.Equal("no", Assert.Single(sseResponse.Headers.GetValues("X-Accel-Buffering")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -92,6 +92,17 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
|
|||
Assert.Equal("text/event-stream", Assert.Single(response.Content.Headers.GetValues("content-type")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SseResponse_Includes_XAccelBufferingHeader()
|
||||
{
|
||||
await StartAsync();
|
||||
|
||||
using var response = await HttpClient.PostAsync("", JsonContent(InitializeRequest), TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("text/event-stream", response.Content.Headers.ContentType?.MediaType);
|
||||
Assert.Equal("no", Assert.Single(response.Headers.GetValues("X-Accel-Buffering")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostRequest_IsUnsupportedMediaType_WithoutJsonContentType()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue