1- using MagicOnion . HttpGateway . Swagger ;
1+ using MagicOnion . HttpGateway . Swagger ;
22using MagicOnion . Server ;
33using Microsoft . AspNetCore . Http ;
44using System . Collections . Generic ;
@@ -24,7 +24,7 @@ public MagicOnionSwaggerMiddleware(RequestDelegate next, IReadOnlyList<MethodHan
2424 this . options = options ;
2525 }
2626
27- public Task Invoke ( HttpContext httpContext )
27+ public async Task Invoke ( HttpContext httpContext )
2828 {
2929 // reference embedded resouces
3030 const string prefix = "MagicOnion.HttpGateway.Swagger.SwaggerUI." ;
@@ -40,8 +40,8 @@ public Task Invoke(HttpContext httpContext)
4040 var bytes = builder . BuildSwaggerJson ( ) ;
4141 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { "application/json" } ;
4242 httpContext . Response . StatusCode = 200 ;
43- httpContext . Response . Body . Write ( bytes , 0 , bytes . Length ) ;
44- return EmptyTask ;
43+ await httpContext . Response . Body . WriteAsync ( bytes , 0 , bytes . Length ) ;
44+ return ;
4545 }
4646
4747 var myAssembly = typeof ( MagicOnionSwaggerMiddleware ) . GetTypeInfo ( ) . Assembly ;
@@ -53,13 +53,14 @@ public Task Invoke(HttpContext httpContext)
5353 if ( stream == null )
5454 {
5555 // not found, standard request.
56- return next ( httpContext ) ;
56+ await next ( httpContext ) ;
57+ return ;
5758 }
5859
5960 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { mediaType } ;
6061 httpContext . Response . StatusCode = 200 ;
6162 var response = httpContext . Response . Body ;
62- stream . CopyTo ( response ) ;
63+ await stream . CopyToAsync ( response ) ;
6364 }
6465 else
6566 {
@@ -72,26 +73,24 @@ public Task Invoke(HttpContext httpContext)
7273 {
7374 using ( var ms = new MemoryStream ( ) )
7475 {
75- stream . CopyTo ( ms ) ;
76+ await stream . CopyToAsync ( ms ) ;
7677 bytes = options . ResolveCustomResource ( path , ms . ToArray ( ) ) ;
7778 }
7879 }
7980
8081 if ( bytes == null )
8182 {
8283 // not found, standard request.
83- return next ( httpContext ) ;
84+ await next ( httpContext ) ;
85+ return ;
8486 }
8587
8688 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { mediaType } ;
8789 httpContext . Response . StatusCode = 200 ;
8890 var response = httpContext . Response . Body ;
89- response . Write ( bytes , 0 , bytes . Length ) ;
91+ await response . WriteAsync ( bytes , 0 , bytes . Length ) ;
9092 }
9193 }
92-
93-
94- return EmptyTask ;
9594 }
9695
9796 static string GetMediaType ( string path )
0 commit comments