diff --git a/src/Microsoft.AspNet.Mvc.Core/PhysicalFileResult.cs b/src/Microsoft.AspNet.Mvc.Core/PhysicalFileResult.cs index 6c343d3fef..0752dd61c6 100644 --- a/src/Microsoft.AspNet.Mvc.Core/PhysicalFileResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/PhysicalFileResult.cs @@ -3,10 +3,8 @@ using System; using System.IO; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Mvc.Core; using Microsoft.Net.Http.Headers; @@ -18,7 +16,6 @@ namespace Microsoft.AspNet.Mvc /// public class PhysicalFileResult : FileResult { - private const int DefaultBufferSize = 0x1000; private string _fileName; /// @@ -83,52 +80,14 @@ namespace Microsoft.AspNet.Mvc } /// - protected override async Task WriteFileAsync(HttpResponse response) + protected override Task WriteFileAsync(HttpResponse response) { if (!Path.IsPathRooted(FileName)) { throw new NotSupportedException(Resources.FormatFileResult_PathNotRooted(FileName)); } - var sendFile = response.HttpContext.Features.Get(); - if (sendFile != null) - { - await sendFile.SendFileAsync( - FileName, - offset: 0, - length: null, - cancellation: default(CancellationToken)); - } - else - { - var fileStream = GetFileStream(FileName); - - using (fileStream) - { - await fileStream.CopyToAsync(response.Body, DefaultBufferSize); - } - } - } - - /// - /// Returns for the specified . - /// - /// The path for which the is needed. - /// for the specified . - protected virtual Stream GetFileStream(string path) - { - if (path == null) - { - throw new ArgumentNullException(nameof(path)); - } - - return new FileStream( - path, - FileMode.Open, - FileAccess.Read, - FileShare.ReadWrite, - DefaultBufferSize, - FileOptions.Asynchronous | FileOptions.SequentialScan); + return response.SendFileAsync(FileName); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/VirtualFileResult.cs b/src/Microsoft.AspNet.Mvc.Core/VirtualFileResult.cs index 5dd5c302a5..96466e7342 100644 --- a/src/Microsoft.AspNet.Mvc.Core/VirtualFileResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/VirtualFileResult.cs @@ -106,14 +106,9 @@ namespace Microsoft.AspNet.Mvc if (fileInfo.Exists) { var physicalPath = fileInfo.PhysicalPath; - var sendFile = response.HttpContext.Features.Get(); - if (sendFile != null && !string.IsNullOrEmpty(physicalPath)) + if (!string.IsNullOrEmpty(physicalPath)) { - await sendFile.SendFileAsync( - physicalPath, - offset: 0, - length: null, - cancellation: default(CancellationToken)); + await response.SendFileAsync(physicalPath); } else {