parent
04c6fceb94
commit
04d72d8894
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
|
|
@ -82,12 +81,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||
protected override Task WriteFileAsync(HttpResponse response)
|
||||
{
|
||||
var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
|
||||
bufferingFeature?.DisableResponseBuffering();
|
||||
|
||||
return response.Body.WriteAsync(FileContents, 0, FileContents.Length, cancellation);
|
||||
return response.Body.WriteAsync(FileContents, offset: 0, count: FileContents.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
|
@ -83,21 +82,16 @@ namespace Microsoft.AspNet.Mvc
|
|||
context.HttpContext.Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
|
||||
}
|
||||
|
||||
// We aren't flowing the cancellation token appropriately, see
|
||||
// https://github.com/aspnet/Mvc/issues/743 for details.
|
||||
return WriteFileAsync(response, CancellationToken.None);
|
||||
return WriteFileAsync(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the file to the response.
|
||||
/// Writes the file to the specified <paramref name="response"/>.
|
||||
/// </summary>
|
||||
/// <param name="response">
|
||||
/// The <see cref="HttpResponse"/> where the file will be written
|
||||
/// </param>
|
||||
/// <param name="cancellation">The <see cref="CancellationToken"/>to cancel the operation.</param>
|
||||
/// <param name="response">The <see cref="HttpResponse"/>.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="Task"/> that will complete when the file has been written to the response.
|
||||
/// </returns>
|
||||
protected abstract Task WriteFileAsync(HttpResponse response, CancellationToken cancellation);
|
||||
protected abstract Task WriteFileAsync(HttpResponse response);
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected async override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||
protected async override Task WriteFileAsync(HttpResponse response)
|
||||
{
|
||||
var outputStream = response.Body;
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
|
||||
bufferingFeature?.DisableResponseBuffering();
|
||||
|
||||
await FileStream.CopyToAsync(outputStream, BufferSize, cancellation);
|
||||
await FileStream.CopyToAsync(outputStream, BufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||
protected override async Task WriteFileAsync(HttpResponse response)
|
||||
{
|
||||
if (!Path.IsPathRooted(FileName))
|
||||
{
|
||||
|
|
@ -97,9 +97,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
FileName,
|
||||
offset: 0,
|
||||
length: null,
|
||||
cancellation: cancellation);
|
||||
|
||||
return;
|
||||
cancellation: default(CancellationToken));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -107,10 +105,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
using (fileStream)
|
||||
{
|
||||
await fileStream.CopyToAsync(response.Body, DefaultBufferSize, cancellation);
|
||||
await fileStream.CopyToAsync(response.Body, DefaultBufferSize);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public IFileProvider FileProvider { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||
protected override async Task WriteFileAsync(HttpResponse response)
|
||||
{
|
||||
var fileProvider = GetFileProvider(response.HttpContext.RequestServices);
|
||||
|
||||
|
|
@ -113,24 +113,22 @@ namespace Microsoft.AspNet.Mvc
|
|||
physicalPath,
|
||||
offset: 0,
|
||||
length: null,
|
||||
cancellation: cancellation);
|
||||
|
||||
return;
|
||||
cancellation: default(CancellationToken));
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileStream = GetFileStream(fileInfo);
|
||||
using (fileStream)
|
||||
{
|
||||
await fileStream.CopyToAsync(response.Body, DefaultBufferSize, cancellation);
|
||||
await fileStream.CopyToAsync(response.Body, DefaultBufferSize);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileNotFoundException(
|
||||
Resources.FormatFileResult_InvalidPath(FileName), FileName);
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
Resources.FormatFileResult_InvalidPath(FileName), FileName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
|
|
@ -227,7 +226,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
}
|
||||
|
||||
protected override Task WriteFileAsync(HttpResponse response, CancellationToken cancellation)
|
||||
protected override Task WriteFileAsync(HttpResponse response)
|
||||
{
|
||||
WasWriteFileCalled = true;
|
||||
return Task.FromResult(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue