11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- using System ;
5- using System . IO ;
6- using System . Threading . Tasks ;
74using Microsoft . AspNetCore . Internal ;
85using Microsoft . Extensions . DependencyInjection ;
96using Microsoft . Extensions . Logging ;
10- using Microsoft . Net . Http . Headers ;
117
128namespace Microsoft . AspNetCore . Http . Result
139{
@@ -24,26 +20,8 @@ internal sealed class FileStreamResult : FileResult, IResult
2420 /// </summary>
2521 /// <param name="fileStream">The stream with the file.</param>
2622 /// <param name="contentType">The Content-Type header of the response.</param>
27- public FileStreamResult ( Stream fileStream , string contentType )
28- : this ( fileStream , MediaTypeHeaderValue . Parse ( contentType ) )
29- {
30- if ( fileStream == null )
31- {
32- throw new ArgumentNullException ( nameof ( fileStream ) ) ;
33- }
34-
35- FileStream = fileStream ;
36- }
37-
38- /// <summary>
39- /// Creates a new <see cref="FileStreamResult"/> instance with
40- /// the provided <paramref name="fileStream"/> and the
41- /// provided <paramref name="contentType"/>.
42- /// </summary>
43- /// <param name="fileStream">The stream with the file.</param>
44- /// <param name="contentType">The Content-Type header of the response.</param>
45- public FileStreamResult ( Stream fileStream , MediaTypeHeaderValue contentType )
46- : base ( contentType . ToString ( ) )
23+ public FileStreamResult ( Stream fileStream , string ? contentType )
24+ : base ( contentType )
4725 {
4826 if ( fileStream == null )
4927 {
@@ -58,10 +36,10 @@ public FileStreamResult(Stream fileStream, MediaTypeHeaderValue contentType)
5836 /// </summary>
5937 public Stream FileStream { get ; }
6038
61- public Task ExecuteAsync ( HttpContext httpContext )
39+ public async Task ExecuteAsync ( HttpContext httpContext )
6240 {
6341 var logger = httpContext . RequestServices . GetRequiredService < ILogger < FileStreamResult > > ( ) ;
64- using ( FileStream )
42+ await using ( FileStream )
6543 {
6644 Log . ExecutingFileResult ( logger , this ) ;
6745
@@ -90,20 +68,20 @@ public Task ExecuteAsync(HttpContext httpContext)
9068
9169 if ( ! serveBody )
9270 {
93- return Task . CompletedTask ;
71+ return ;
9472 }
9573
9674 if ( range != null && rangeLength == 0 )
9775 {
98- return Task . CompletedTask ;
76+ return ;
9977 }
10078
10179 if ( range != null )
10280 {
10381 FileResultHelper . Log . WritingRangeToBody ( logger ) ;
10482 }
10583
106- return FileResultHelper . WriteFileAsync ( httpContext , FileStream , range , rangeLength ) ;
84+ await FileResultHelper . WriteFileAsync ( httpContext , FileStream , range , rangeLength ) ;
10785 }
10886 }
10987 }
0 commit comments