Skip to content

Commit

Permalink
Create HttpCachePolicyBase, fix HttpResponseBase.Cache typing (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvremelM authored Jul 11, 2024
1 parent c2607be commit 649e737
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ internal HttpCachePolicy() { }
public void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public partial class HttpCachePolicyBase
{
public HttpCachePolicyBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Web.HttpCacheVaryByHeaders VaryByHeaders { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual void SetCacheability(System.Web.HttpCacheability cacheability) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
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");}
public virtual void SetExpires(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual void SetLastModified(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public partial class HttpCachePolicyWrapper : System.Web.HttpCachePolicyBase
{
public HttpCachePolicyWrapper(System.Web.HttpCachePolicy httpCachePolicy) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override System.Web.HttpCacheVaryByHeaders VaryByHeaders { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override void SetCacheability(System.Web.HttpCacheability cacheability) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override void SetExpires(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override void SetLastModified(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override void SetOmitVaryStar(bool omit) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public sealed partial class HttpCacheVaryByHeaders
{
internal HttpCacheVaryByHeaders() { }
Expand Down Expand Up @@ -535,7 +556,7 @@ public partial class HttpResponseBase
{
public HttpResponseBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual bool BufferOutput { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpCachePolicy Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpCachePolicyBase Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
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");} }
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");} }
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");} }
Expand Down Expand Up @@ -579,7 +600,7 @@ public partial class HttpResponseWrapper : System.Web.HttpResponseBase
{
public HttpResponseWrapper(System.Web.HttpResponse response) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override bool BufferOutput { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpCachePolicy Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpCachePolicyBase Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
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");} }
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");} }
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");} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesWrapper))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheability))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicy))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCachePolicyWrapper))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCacheVaryByHeaders))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContext))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpContextBase))]
Expand Down
28 changes: 28 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace System.Web;

public class HttpCachePolicyBase
{
[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
public virtual HttpCacheVaryByHeaders VaryByHeaders => throw new NotImplementedException();

public virtual void SetCacheability(HttpCacheability cacheability) => throw new NotImplementedException();

public virtual void SetCacheability(HttpCacheability cacheability, string field) => throw new NotImplementedException();

[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
Justification = "Matches HttpCachePolicy class")]
public virtual void SetLastModified(DateTime date) => throw new NotImplementedException();

public virtual void SetMaxAge(TimeSpan delta) => throw new NotImplementedException();

[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
Justification = "Matches HttpCachePolicy class")]
public virtual void SetExpires(DateTime date) => throw new NotImplementedException();

public virtual void SetOmitVaryStar(bool omit) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Web;

public class HttpCachePolicyWrapper : HttpCachePolicyBase
{
private HttpCachePolicy _httpCachePolicy;

public HttpCachePolicyWrapper(HttpCachePolicy httpCachePolicy)
{
if (httpCachePolicy == null)
{
ArgumentNullException.ThrowIfNull(httpCachePolicy);
}
_httpCachePolicy = httpCachePolicy;
}


public override HttpCacheVaryByHeaders VaryByHeaders => _httpCachePolicy.VaryByHeaders;

public override void SetCacheability(HttpCacheability cacheability) => _httpCachePolicy.SetCacheability(cacheability);

public override void SetExpires(DateTime date) => _httpCachePolicy.SetExpires(date);

public override void SetLastModified(DateTime date) => _httpCachePolicy.SetLastModified(date);

public override void SetMaxAge(TimeSpan delta) => _httpCachePolicy.SetMaxAge(delta);

public override void SetOmitVaryStar(bool omit) => _httpCachePolicy.SetOmitVaryStar(omit);

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public virtual Stream Filter
set => throw new NotImplementedException();
}

public virtual HttpCachePolicy Cache => throw new NotImplementedException();
public virtual HttpCachePolicyBase Cache => throw new NotImplementedException();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override bool TrySkipIisCustomErrors
set => _response.TrySkipIisCustomErrors = value;
}

public override HttpCachePolicy Cache => _response.Cache;
public override HttpCachePolicyBase Cache => new HttpCachePolicyWrapper(_response.Cache);

[AllowNull]
public override Stream Filter
Expand Down

0 comments on commit 649e737

Please sign in to comment.