From fe7ffa6b56630e7006e50a98ea27df7c0640522a Mon Sep 17 00:00:00 2001 From: Ruoyun Tang Date: Wed, 12 Jul 2023 14:36:49 +0800 Subject: [PATCH 1/3] close #365: add HttpCapabilitiesBase.Cookies --- .../Configuration/HttpCapabilitiesBase.cs | 3 +++ .../Generated/Ref.Standard.cs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs index 572d067a92..7bad5463cb 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Globalization; +using System.Net; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.SystemWebAdapters; using Microsoft.Extensions.DependencyInjection; @@ -45,6 +46,8 @@ private IHttpBrowserCapabilityFeature Capability public bool Crawler => GetBoolean("crawler"); + public bool Cookies => GetBoolean("cookies"); + public string? Type => Capability["type"]; public string? PreferredRequestEncoding => Capability["preferredRequestEncoding"]; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index ee06b9a36b..49c48f9cec 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -722,6 +722,7 @@ public partial class HttpCapabilitiesBase { internal HttpCapabilitiesBase() { } public string Browser { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public bool Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool Crawler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool IsMobileDevice { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public string this[string key] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } From be99ba7190c1b4888f1a48623e51a0cdcb6645e7 Mon Sep 17 00:00:00 2001 From: Ruoyun Tang Date: Thu, 13 Jul 2023 10:02:52 +0800 Subject: [PATCH 2/3] remove unnecessary using --- .../Configuration/HttpCapabilitiesBase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs index 7bad5463cb..af664ae5e9 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Globalization; -using System.Net; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.SystemWebAdapters; using Microsoft.Extensions.DependencyInjection; From 405f0e82baf0d2a754e768e5792107318069f271 Mon Sep 17 00:00:00 2001 From: Ruoyun Tang Date: Wed, 26 Jul 2023 17:27:37 +0800 Subject: [PATCH 3/3] add httpResponse.HeadersWritten --- .../Generated/Ref.Standard.cs | 3 +++ .../HttpResponse.cs | 5 +++++ .../HttpResponseBase.cs | 8 ++++++++ .../HttpResponseWrapper.cs | 3 +++ 4 files changed, 19 insertions(+) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index 49c48f9cec..f2f93e5670 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -427,6 +427,7 @@ internal HttpResponse() { } public 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");} } public System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public bool HeadersWritten { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool IsClientConnected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool IsRequestBeingRedirected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public System.IO.TextWriter Output { 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");} } @@ -467,6 +468,7 @@ public partial class HttpResponseBase 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");} } public virtual System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual bool HeadersWritten { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual bool IsClientConnected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual bool IsRequestBeingRedirected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.IO.TextWriter Output { 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");} } @@ -500,6 +502,7 @@ public partial class HttpResponseWrapper : System.Web.HttpResponseBase 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");} } public override System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override bool HeadersWritten { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override bool IsClientConnected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override bool IsRequestBeingRedirected { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.IO.TextWriter Output { 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");} } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs index 06246ae541..93fcffad02 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs @@ -178,6 +178,11 @@ public void AppendHeader(string name, string value) } } + public bool HeadersWritten + { + get => _response.HasStarted; + } + public string RedirectLocation { get => _response.Headers.Location; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs index c9b2726c30..992e93cc8f 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs @@ -35,6 +35,14 @@ public virtual NameValueCollection Headers get => throw new NotImplementedException(); } + public virtual bool HeadersWritten + { + get + { + throw new NotImplementedException(); + } + } + public virtual bool TrySkipIisCustomErrors { get => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseWrapper.cs index 80d8d406cc..6cc2fc589b 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseWrapper.cs @@ -4,6 +4,7 @@ using System.Collections.Specialized; using System.IO; using System.Text; +using Microsoft.AspNetCore.Http; namespace System.Web { @@ -47,6 +48,8 @@ public override HttpCookieCollection Cookies public override NameValueCollection Headers => _response.Headers; + public override bool HeadersWritten => _response.HeadersWritten; + public override bool IsClientConnected => _response.IsClientConnected; public override TextWriter Output