@@ -26,7 +26,7 @@ public BatchEngineSwaggerMiddleware(RequestDelegate next, TargetBatchTypeCollect
2626 this . options = options ;
2727 }
2828
29- public Task Invoke ( HttpContext httpContext )
29+ public async Task Invoke ( HttpContext httpContext )
3030 {
3131 // reference embedded resouces
3232 const string prefix = "MicroBatchFramework.WebHosting.Swagger.SwaggerUI." ;
@@ -42,8 +42,8 @@ public Task Invoke(HttpContext httpContext)
4242 var bytes = builder . BuildSwaggerJson ( ) ;
4343 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { "application/json" } ;
4444 httpContext . Response . StatusCode = 200 ;
45- httpContext . Response . Body . Write ( bytes , 0 , bytes . Length ) ;
46- return EmptyTask ;
45+ await httpContext . Response . Body . WriteAsync ( bytes , 0 , bytes . Length ) ;
46+ return ;
4747 }
4848
4949 var myAssembly = typeof ( BatchEngineSwaggerMiddleware ) . GetTypeInfo ( ) . Assembly ;
@@ -55,13 +55,14 @@ public Task Invoke(HttpContext httpContext)
5555 if ( stream == null )
5656 {
5757 // not found, standard request.
58- return next ( httpContext ) ;
58+ await next ( httpContext ) ;
59+ return ;
5960 }
6061
6162 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { mediaType } ;
6263 httpContext . Response . StatusCode = 200 ;
6364 var response = httpContext . Response . Body ;
64- stream . CopyTo ( response ) ;
65+ await stream . CopyToAsync ( response ) ;
6566 }
6667 else
6768 {
@@ -74,26 +75,24 @@ public Task Invoke(HttpContext httpContext)
7475 {
7576 using ( var ms = new MemoryStream ( ) )
7677 {
77- stream . CopyTo ( ms ) ;
78+ await stream . CopyToAsync ( ms ) ;
7879 bytes = options . ResolveCustomResource ( path , ms . ToArray ( ) ) ;
7980 }
8081 }
8182
8283 if ( bytes == null )
8384 {
8485 // not found, standard request.
85- return next ( httpContext ) ;
86+ await next ( httpContext ) ;
87+ return ;
8688 }
8789
8890 httpContext . Response . Headers [ "Content-Type" ] = new [ ] { mediaType } ;
8991 httpContext . Response . StatusCode = 200 ;
9092 var response = httpContext . Response . Body ;
91- response . Write ( bytes , 0 , bytes . Length ) ;
93+ await response . WriteAsync ( bytes , 0 , bytes . Length ) ;
9294 }
9395 }
94-
95-
96- return EmptyTask ;
9796 }
9897
9998 static string GetMediaType ( string path )
0 commit comments