Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public async Task InvokeAsync(HttpContextCore context)
}
finally
{
await context.Features.GetRequiredFeature<IHttpResponseBufferingFeature>().FlushAsync();
// The buffering feature may be removed if the response has ended i.e in usage with YARP
if (context.Features.Get<IHttpResponseBufferingFeature>() is { } buffer)
{
await buffer.FlushAsync();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ public async Task BufferingCanBeDisabledAndFlushesUsingPipe()
Assert.Equal("before after", result);
}

[Fact]
public async Task BufferIsNotFlushedIfNotAvailable()
{
var result = await RunAsync(middleware: (ctx, next) =>
{
ctx.Features.Set<IHttpResponseBufferingFeature>(null);
return next(ctx);
});

Assert.Equal(string.Empty, result);
}

private static Task<string> RunAsync(Action<HttpContext> action, Action<IEndpointConventionBuilder>? builder = null, Func<Http.HttpContext, RequestDelegate, Task>? middleware = null)
=> RunAsync(ctx =>
{
Expand Down