File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
src/Microsoft.AspNetCore.SystemWebAdapters.CoreServices/Features
test/Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ bool IHttpResponseBufferingFeature.IsEnabled
9191
9292 private async ValueTask FlushInternalAsync ( )
9393 {
94+ if ( _pipeWriter is { } )
95+ {
96+ await _pipeWriter . FlushAsync ( ) ;
97+ }
98+
9499 if ( _state is StreamState . Buffering && _bufferedStream is not null && ! SuppressContent )
95100 {
96101 if ( _filter is { } filter )
@@ -111,7 +116,23 @@ private async ValueTask FlushInternalAsync()
111116
112117 Stream IHttpResponseBodyFeature . Stream => this ;
113118
114- PipeWriter IHttpResponseBodyFeature . Writer => _pipeWriter ??= PipeWriter . Create ( this , new StreamPipeWriterOptions ( leaveOpen : true ) ) ;
119+ PipeWriter IHttpResponseBodyFeature . Writer
120+ {
121+ get
122+ {
123+ if ( _pipeWriter is null )
124+ {
125+ _pipeWriter = PipeWriter . Create ( this , new StreamPipeWriterOptions ( leaveOpen : true ) ) ;
126+
127+ if ( _state is StreamState . Complete )
128+ {
129+ _pipeWriter . Complete ( ) ;
130+ }
131+ }
132+
133+ return _pipeWriter ;
134+ }
135+ }
115136
116137 public bool SuppressContent
117138 {
@@ -229,6 +250,11 @@ private async Task CompleteAsync()
229250
230251 _state = StreamState . Complete ;
231252
253+ if ( _pipeWriter is { } )
254+ {
255+ await _pipeWriter . CompleteAsync ( ) ;
256+ }
257+
232258 await _responseBodyFeature . CompleteAsync ( ) ;
233259 }
234260
Original file line number Diff line number Diff line change 22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
5+ using System . Buffers ;
56using System . Collections . Generic ;
67using System . IO ;
78using System . Text ;
@@ -42,6 +43,19 @@ public async Task BufferedOutputIsFlushed()
4243 Assert . Equal ( ContentValue , result ) ;
4344 }
4445
46+ [ Fact ]
47+ public async Task OutputPipeIsFlushed ( )
48+ {
49+ const string Message = "hello world from pipe!" ;
50+
51+ var result = await RunAsync ( context =>
52+ {
53+ context . AsAspNetCore ( ) . Response . BodyWriter . Write ( Encoding . UTF8 . GetBytes ( Message ) ) ;
54+ } ) ;
55+
56+ Assert . Equal ( Message , result ) ;
57+ }
58+
4559 [ Fact ]
4660 public async Task BufferedOutputIsFlushedOnceWithStart ( )
4761 {
You can’t perform that action at this time.
0 commit comments