1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
+ using System ;
4
5
using System . IO ;
6
+ using System . IO . Pipelines ;
5
7
using System . Net ;
6
8
using System . Text ;
7
9
using System . Threading . Tasks ;
@@ -16,18 +18,26 @@ public class Startup
16
18
17
19
public void Configure ( IApplicationBuilder app )
18
20
{
19
- app . Run ( ( httpContext ) =>
21
+ app . Run ( async ( httpContext ) =>
20
22
{
21
23
var response = httpContext . Response ;
22
24
response . StatusCode = 200 ;
23
25
response . ContentType = "text/plain" ;
26
+ response . ContentLength = _helloWorldBytes . Length ;
24
27
25
- var helloWorld = _helloWorldBytes ;
26
- response . ContentLength = helloWorld . Length ;
27
- return response . Body . WriteAsync ( helloWorld , 0 , helloWorld . Length ) ;
28
+ var pipe = response . BodyPipe ;
29
+ Write ( pipe , _helloWorldBytes ) ;
30
+ await pipe . FlushAsync ( ) ;
28
31
} ) ;
29
32
}
30
33
34
+ private static void Write ( PipeWriter pipe , byte [ ] payload )
35
+ {
36
+ var span = pipe . GetSpan ( sizeHint : payload . Length ) ;
37
+ payload . CopyTo ( span ) ;
38
+ pipe . Advance ( payload . Length ) ;
39
+ }
40
+
31
41
public static Task Main ( string [ ] args )
32
42
{
33
43
var host = new WebHostBuilder ( )
0 commit comments