Skip to content

Commit 4c17aef

Browse files
authored
Add support for more APIs on HttpCachePolicy (#584)
Fixes #507
1 parent a9438ff commit 4c17aef

File tree

21 files changed

+3366
-227
lines changed

21 files changed

+3366
-227
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,27 @@
66

77
namespace Microsoft.AspNetCore.SystemWebAdapters;
88

9-
/// <summary>
10-
/// System.Web would set some response headers by default. This adds those early in the pipeline so they can still be overridden. If they exist, they will not be replaced.
11-
/// </summary>
12-
internal class SetDefaultResponseHeadersMiddleware
9+
internal sealed class CachePolicyMiddleware(RequestDelegate next)
1310
{
14-
private readonly RequestDelegate _next;
15-
16-
public SetDefaultResponseHeadersMiddleware(RequestDelegate next) => _next = next;
17-
1811
public Task InvokeAsync(HttpContext context)
1912
{
2013
context.Response.OnStarting(static state =>
2114
{
2215
var context = (HttpContext)state;
2316

2417
WriteDefaultContentType(context);
25-
context.Response.AsSystemWeb().Cache.UpdateHeaders();
18+
19+
context.Response.AsSystemWeb().ApplyCachePolicy();
2620

2721
return Task.CompletedTask;
2822
}, context);
2923

30-
return _next(context);
24+
return next(context);
3125
}
3226

27+
/// <summary>
28+
/// System.Web would set some response headers by default. This adds those early in the pipeline so they can still be overridden. If they exist, they will not be replaced.
29+
/// </summary>
3330
private static void WriteDefaultContentType(HttpContext context)
3431
{
3532
if (context.Response.ContentLength.HasValue && context.Response.Headers.ContentType.Count == 0)

src/Microsoft.AspNetCore.SystemWebAdapters.CoreServices/SystemWebAdaptersExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal static void UseSystemWebAdapterFeatures(this IApplicationBuilder app)
7171

7272
app.UseMiddleware<PreBufferRequestStreamMiddleware>();
7373
app.UseMiddleware<BufferResponseStreamMiddleware>();
74-
app.UseMiddleware<SetDefaultResponseHeadersMiddleware>();
74+
app.UseMiddleware<CachePolicyMiddleware>();
7575
app.UseMiddleware<SingleThreadedRequestMiddleware>();
7676
app.UseMiddleware<CurrentPrincipalMiddleware>();
7777

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs

Lines changed: 97 additions & 4 deletions
Large diffs are not rendered by default.

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicy))]
3232
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyBase))]
3333
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyWrapper))]
34+
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheRevalidation))]
35+
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheVaryByContentEncodings))]
3436
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheVaryByHeaders))]
37+
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheVaryByParams))]
3538
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContext))]
3639
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContextBase))]
3740
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContextWrapper))]

0 commit comments

Comments
 (0)