make StaticFileResponseContext constructable (#250)

* make StaticFileResponseContext constructible so people can instantiate it for testing purposes
This commit is contained in:
Simon Cropp 2018-09-28 13:32:58 +10:00 committed by Chris Ross
parent 1380326811
commit df1f72d3d2
2 changed files with 23 additions and 7 deletions

View File

@ -282,11 +282,7 @@ namespace Microsoft.AspNetCore.StaticFiles
// it is not returned for 304, 412, and 416 // it is not returned for 304, 412, and 416
_response.ContentLength = _length; _response.ContentLength = _length;
} }
_options.OnPrepareResponse(new StaticFileResponseContext() _options.OnPrepareResponse(new StaticFileResponseContext(_context, _fileInfo));
{
Context = _context,
File = _fileInfo,
});
} }
public PreconditionState GetPreconditionState() public PreconditionState GetPreconditionState()

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
@ -11,14 +12,33 @@ namespace Microsoft.AspNetCore.StaticFiles
/// </summary> /// </summary>
public class StaticFileResponseContext public class StaticFileResponseContext
{ {
[Obsolete("Use the constructor that passes in the HttpContext and IFileInfo parameters: StaticFileResponseContext(HttpContext context, IFileInfo file)", false)]
public StaticFileResponseContext()
{
}
public StaticFileResponseContext(HttpContext context, IFileInfo file)
{
if (file == null)
{
throw new ArgumentNullException(nameof(file));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
Context = context;
File = file;
}
/// <summary> /// <summary>
/// The request and response information. /// The request and response information.
/// </summary> /// </summary>
public HttpContext Context { get; internal set; } public HttpContext Context { get; }
/// <summary> /// <summary>
/// The file to be served. /// The file to be served.
/// </summary> /// </summary>
public IFileInfo File { get; internal set; } public IFileInfo File { get; }
} }
} }