Commit dd0a6e6 1 parent e2fc2b8 commit dd0a6e6 Copy full SHA for dd0a6e6
File tree 2 files changed +41
-1
lines changed
src/Microsoft.AspNetCore.SystemWebAdapters.CoreServices/Features
test/Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ bool IHttpResponseBufferingFeature.IsEnabled
91
91
92
92
private async ValueTask FlushInternalAsync ( )
93
93
{
94
+ if ( _pipeWriter is { } )
95
+ {
96
+ await _pipeWriter . FlushAsync ( ) ;
97
+ }
98
+
94
99
if ( _state is StreamState . Buffering && _bufferedStream is not null && ! SuppressContent )
95
100
{
96
101
if ( _filter is { } filter )
@@ -111,7 +116,23 @@ private async ValueTask FlushInternalAsync()
111
116
112
117
Stream IHttpResponseBodyFeature . Stream => this ;
113
118
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
+ }
115
136
116
137
public bool SuppressContent
117
138
{
@@ -229,6 +250,11 @@ private async Task CompleteAsync()
229
250
230
251
_state = StreamState . Complete ;
231
252
253
+ if ( _pipeWriter is { } )
254
+ {
255
+ await _pipeWriter . CompleteAsync ( ) ;
256
+ }
257
+
232
258
await _responseBodyFeature . CompleteAsync ( ) ;
233
259
}
234
260
Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
+ using System . Buffers ;
5
6
using System . Collections . Generic ;
6
7
using System . IO ;
7
8
using System . Text ;
@@ -42,6 +43,19 @@ public async Task BufferedOutputIsFlushed()
42
43
Assert . Equal ( ContentValue , result ) ;
43
44
}
44
45
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
+
45
59
[ Fact ]
46
60
public async Task BufferedOutputIsFlushedOnceWithStart ( )
47
61
{
You can’t perform that action at this time.
0 commit comments