Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HttpResponseBase.Cache typing (Fixes #476) #477

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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 @@ -504,7 +525,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 @@ -541,7 +562,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 @@ -26,6 +26,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 @@ -96,7 +96,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