diff --git a/src/Microsoft.AspNetCore.StaticFiles/StaticFileContext.cs b/src/Microsoft.AspNetCore.StaticFiles/StaticFileContext.cs index f5024dcb23..eac316e6c7 100644 --- a/src/Microsoft.AspNetCore.StaticFiles/StaticFileContext.cs +++ b/src/Microsoft.AspNetCore.StaticFiles/StaticFileContext.cs @@ -282,11 +282,7 @@ namespace Microsoft.AspNetCore.StaticFiles // it is not returned for 304, 412, and 416 _response.ContentLength = _length; } - _options.OnPrepareResponse(new StaticFileResponseContext() - { - Context = _context, - File = _fileInfo, - }); + _options.OnPrepareResponse(new StaticFileResponseContext(_context, _fileInfo)); } public PreconditionState GetPreconditionState() diff --git a/src/Microsoft.AspNetCore.StaticFiles/StaticFileResponseContext.cs b/src/Microsoft.AspNetCore.StaticFiles/StaticFileResponseContext.cs index 72b25c8259..a9743fdfa0 100644 --- a/src/Microsoft.AspNetCore.StaticFiles/StaticFileResponseContext.cs +++ b/src/Microsoft.AspNetCore.StaticFiles/StaticFileResponseContext.cs @@ -1,6 +1,7 @@ // 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. +using System; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.FileProviders; @@ -11,14 +12,33 @@ namespace Microsoft.AspNetCore.StaticFiles /// 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; + } + /// /// The request and response information. /// - public HttpContext Context { get; internal set; } + public HttpContext Context { get; } /// /// The file to be served. /// - public IFileInfo File { get; internal set; } + public IFileInfo File { get; } } }