Skip to content

Commit 649e737

Browse files
authored
Create HttpCachePolicyBase, fix HttpResponseBase.Cache typing (#477)
1 parent c2607be commit 649e737

File tree

6 files changed

+87
-4
lines changed

6 files changed

+87
-4
lines changed

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

+23-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ internal HttpCachePolicy() { }
126126
public void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
127127
public void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
128128
}
129+
public partial class HttpCachePolicyBase
130+
{
131+
public HttpCachePolicyBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
132+
public virtual System.Web.HttpCacheVaryByHeaders VaryByHeaders { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
133+
public virtual void SetCacheability(System.Web.HttpCacheability cacheability) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
134+
public virtual void SetCacheability(System.Web.HttpCacheability cacheability, string field) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
135+
public virtual void SetExpires(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
136+
public virtual void SetLastModified(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
137+
public virtual void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
138+
public virtual void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
139+
}
140+
public partial class HttpCachePolicyWrapper : System.Web.HttpCachePolicyBase
141+
{
142+
public HttpCachePolicyWrapper(System.Web.HttpCachePolicy httpCachePolicy) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
143+
public override System.Web.HttpCacheVaryByHeaders VaryByHeaders { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
144+
public override void SetCacheability(System.Web.HttpCacheability cacheability) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
145+
public override void SetExpires(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
146+
public override void SetLastModified(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
147+
public override void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
148+
public override void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
149+
}
129150
public sealed partial class HttpCacheVaryByHeaders
130151
{
131152
internal HttpCacheVaryByHeaders() { }
@@ -535,7 +556,7 @@ public partial class HttpResponseBase
535556
{
536557
public HttpResponseBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
537558
public virtual bool BufferOutput { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
538-
public virtual System.Web.HttpCachePolicy Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
559+
public virtual System.Web.HttpCachePolicyBase Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
539560
public virtual string Charset { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
540561
public virtual System.Text.Encoding ContentEncoding { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
541562
public virtual string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
@@ -579,7 +600,7 @@ public partial class HttpResponseWrapper : System.Web.HttpResponseBase
579600
{
580601
public HttpResponseWrapper(System.Web.HttpResponse response) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
581602
public override bool BufferOutput { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
582-
public override System.Web.HttpCachePolicy Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
603+
public override System.Web.HttpCachePolicyBase Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
583604
public override string Charset { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
584605
public override System.Text.Encoding ContentEncoding { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
585606
public override string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }

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

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesWrapper))]
2828
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheability))]
2929
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicy))]
30+
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyBase))]
31+
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyWrapper))]
3032
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheVaryByHeaders))]
3133
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContext))]
3234
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContextBase))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace System.Web;
7+
8+
public class HttpCachePolicyBase
9+
{
10+
[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
11+
public virtual HttpCacheVaryByHeaders VaryByHeaders => throw new NotImplementedException();
12+
13+
public virtual void SetCacheability(HttpCacheability cacheability) => throw new NotImplementedException();
14+
15+
public virtual void SetCacheability(HttpCacheability cacheability, string field) => throw new NotImplementedException();
16+
17+
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
18+
Justification = "Matches HttpCachePolicy class")]
19+
public virtual void SetLastModified(DateTime date) => throw new NotImplementedException();
20+
21+
public virtual void SetMaxAge(TimeSpan delta) => throw new NotImplementedException();
22+
23+
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
24+
Justification = "Matches HttpCachePolicy class")]
25+
public virtual void SetExpires(DateTime date) => throw new NotImplementedException();
26+
27+
public virtual void SetOmitVaryStar(bool omit) => throw new NotImplementedException();
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Web;
5+
6+
public class HttpCachePolicyWrapper : HttpCachePolicyBase
7+
{
8+
private HttpCachePolicy _httpCachePolicy;
9+
10+
public HttpCachePolicyWrapper(HttpCachePolicy httpCachePolicy)
11+
{
12+
if (httpCachePolicy == null)
13+
{
14+
ArgumentNullException.ThrowIfNull(httpCachePolicy);
15+
}
16+
_httpCachePolicy = httpCachePolicy;
17+
}
18+
19+
20+
public override HttpCacheVaryByHeaders VaryByHeaders => _httpCachePolicy.VaryByHeaders;
21+
22+
public override void SetCacheability(HttpCacheability cacheability) => _httpCachePolicy.SetCacheability(cacheability);
23+
24+
public override void SetExpires(DateTime date) => _httpCachePolicy.SetExpires(date);
25+
26+
public override void SetLastModified(DateTime date) => _httpCachePolicy.SetLastModified(date);
27+
28+
public override void SetMaxAge(TimeSpan delta) => _httpCachePolicy.SetMaxAge(delta);
29+
30+
public override void SetOmitVaryStar(bool omit) => _httpCachePolicy.SetOmitVaryStar(omit);
31+
32+
}

src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public virtual Stream Filter
9797
set => throw new NotImplementedException();
9898
}
9999

100-
public virtual HttpCachePolicy Cache => throw new NotImplementedException();
100+
public virtual HttpCachePolicyBase Cache => throw new NotImplementedException();
101101

102102
public virtual bool IsClientConnected => throw new NotImplementedException();
103103

src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseWrapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public override bool TrySkipIisCustomErrors
9999
set => _response.TrySkipIisCustomErrors = value;
100100
}
101101

102-
public override HttpCachePolicy Cache => _response.Cache;
102+
public override HttpCachePolicyBase Cache => new HttpCachePolicyWrapper(_response.Cache);
103103

104104
[AllowNull]
105105
public override Stream Filter

0 commit comments

Comments
 (0)