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

Modify System.Net.HttpListener to throw PNSE at assembly level on browser #43401

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,5 +3,6 @@
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public HttpListener() { }
public System.Net.AuthenticationSchemes AuthenticationSchemes { get { throw null; } set { } }
public System.Net.AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate { get { throw null; } set { } }
public System.Security.Authentication.ExtendedProtection.ServiceNameCollection DefaultServiceNames { get { throw null; } }
public System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy ExtendedProtectionPolicy { get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
public System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy ExtendedProtectionPolicy { get { throw null; } set { } }
[System.Diagnostics.CodeAnalysis.DisallowNullAttribute]
public System.Net.HttpListener.ExtendedProtectionSelector? ExtendedProtectionSelectorDelegate { get { throw null; } set { } }
public bool IgnoreWriteExceptions { get { throw null; } set { } }
Expand Down Expand Up @@ -87,25 +87,21 @@ internal HttpListenerRequest() { }
public string HttpMethod { get { throw null; } }
public System.IO.Stream InputStream { get { throw null; } }
public bool IsAuthenticated { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public bool IsLocal { get { throw null; } }
public bool IsSecureConnection { get { throw null; } }
public bool IsWebSocketRequest { get { throw null; } }
public bool KeepAlive { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.IPEndPoint LocalEndPoint { get { throw null; } }
public System.Version ProtocolVersion { get { throw null; } }
public System.Collections.Specialized.NameValueCollection QueryString { get { throw null; } }
public string? RawUrl { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.IPEndPoint RemoteEndPoint { get { throw null; } }
public System.Guid RequestTraceIdentifier { get { throw null; } }
public string? ServiceName { get { throw null; } }
public System.Net.TransportContext TransportContext { get { throw null; } }
public System.Uri? Url { get { throw null; } }
public System.Uri? UrlReferrer { get { throw null; } }
public string UserAgent { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public string UserHostAddress { get { throw null; } }
public string UserHostName { get { throw null; } }
public string[]? UserLanguages { get { throw null; } }
Expand All @@ -129,14 +125,11 @@ internal HttpListenerResponse() { }
public bool SendChunked { get { throw null; } set { } }
public int StatusCode { get { throw null; } set { } }
public string StatusDescription { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Abort() { }
public void AddHeader(string name, string value) { }
public void AppendCookie(System.Net.Cookie cookie) { }
public void AppendHeader(string name, string value) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Close() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Close(byte[] responseEntity, bool willBlock) { }
public void CopyFrom(System.Net.HttpListenerResponse templateResponse) { }
public void Redirect(string url) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,7 @@
<data name="net_WebSockets_InvalidState" xml:space="preserve">
<value>The WebSocket is in an invalid state ('{0}') for this operation. Valid states are: '{1}'</value>
</data>
<data name="SystemNetHttpListener_PlatformNotSupported" xml:space="preserve">
<value>System.Net.HttpListener is not supported on this platform.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<ForceManagedImplementation>false</ForceManagedImplementation>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<Nullable>enable</Nullable>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsBrowser)' == 'true'">SR.SystemNetHttpListener_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' != 'true'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Principal.Windows\src\System.Security.Principal.Windows.csproj" />
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
Expand Down Expand Up @@ -33,7 +34,7 @@
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Overlapped" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' != 'true'">
<Compile Include="System\Net\BoundaryType.cs" />
<Compile Include="System\Net\EntitySendFormat.cs" />
<Compile Include="System\Net\HttpListenerPrefixCollection.cs" />
Expand Down Expand Up @@ -247,7 +248,7 @@
<Compile Include="$(CommonPath)Interop\Windows\SspiCli\SSPIWrapper.cs"
Link="Common\Interop\Windows\SspiCli\SSPIWrapper.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(ForceManagedImplementation)' == 'true'">
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(ForceManagedImplementation)' == 'true' and '$(TargetsBrowser)' != 'true'">
MaximLipnin marked this conversation as resolved.
Show resolved Hide resolved
<Compile Include="System\Net\Managed\HttpEndPointListener.cs" />
<Compile Include="System\Net\Managed\HttpEndPointManager.cs" />
<Compile Include="System\Net\Managed\HttpConnection.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;
using System.Security.Authentication.ExtendedProtection;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -82,7 +81,6 @@ public AuthenticationSchemes AuthenticationSchemes
public ExtendedProtectionPolicy ExtendedProtectionPolicy
{
get => _extendedProtectionPolicy;
[UnsupportedOSPlatform("browser")]
set
{
CheckDisposed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Globalization;
using System.Net.WebSockets;
using System.Reflection;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -111,7 +110,7 @@ public Encoding ContentEncoding

public string? ContentType => Headers[HttpKnownHeaderNames.ContentType];

[UnsupportedOSPlatform("browser")]

public bool IsLocal => LocalEndPoint!.Address.Equals(RemoteEndPoint!.Address);

public bool IsWebSocketRequest
Expand Down Expand Up @@ -208,7 +207,7 @@ public NameValueCollection QueryString

public string UserAgent => Headers[HttpKnownHeaderNames.UserAgent]!;

[UnsupportedOSPlatform("browser")]

public string UserHostAddress => LocalEndPoint!.ToString();

public string UserHostName => Headers[HttpKnownHeaderNames.Host]!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.Versioning;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
Expand Down Expand Up @@ -375,10 +374,8 @@ public Stream InputStream

public bool IsSecureConnection => _context.Connection.IsSecure;

[UnsupportedOSPlatform("browser")]
public IPEndPoint? LocalEndPoint => _context.Connection.LocalEndPoint;

[UnsupportedOSPlatform("browser")]
public IPEndPoint? RemoteEndPoint => _context.Connection.RemoteEndPoint;

public Guid RequestTraceIdentifier { get; } = Guid.NewGuid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

using System.Globalization;
using System.IO;
using System.Runtime.Versioning;
using System.Text;

namespace System.Net
Expand Down Expand Up @@ -94,7 +93,6 @@ public int StatusCode

private void Dispose() => Close(true);

[UnsupportedOSPlatform("browser")]
public void Close()
{
if (Disposed)
Expand All @@ -103,7 +101,6 @@ public void Close()
Close(false);
}

[UnsupportedOSPlatform("browser")]
public void Abort()
{
if (Disposed)
Expand All @@ -118,7 +115,6 @@ private void Close(bool force)
_httpContext!.Connection.Close(force);
}

[UnsupportedOSPlatform("browser")]
public void Close(byte[] responseEntity, bool willBlock)
{
CheckDisposed();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

MaximLipnin marked this conversation as resolved.
Show resolved Hide resolved
namespace System.Net
{
public class HttpListenerTimeoutManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.IO;
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Cryptography;
Expand Down Expand Up @@ -289,7 +288,6 @@ public bool HasEntityBody
}
}

[UnsupportedOSPlatform("browser")]
public IPEndPoint RemoteEndPoint
{
get
Expand All @@ -303,7 +301,6 @@ public IPEndPoint RemoteEndPoint
}
}

[UnsupportedOSPlatform("browser")]
public IPEndPoint LocalEndPoint
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Versioning;
using Microsoft.Win32.SafeHandles;

namespace System.Net
Expand Down Expand Up @@ -96,7 +95,6 @@ public Version ProtocolVersion
}
}

[UnsupportedOSPlatform("browser")]
public void Abort()
{
if (Disposed)
Expand All @@ -108,7 +106,6 @@ public void Abort()
HttpListenerContext.Abort();
}

[UnsupportedOSPlatform("browser")]
public void Close()
{
try
Expand All @@ -121,7 +118,6 @@ public void Close()
}
}

[UnsupportedOSPlatform("browser")]
public void Close(byte[] responseEntity, bool willBlock)
{
CheckDisposed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Versioning;
MaximLipnin marked this conversation as resolved.
Show resolved Hide resolved

namespace System.Net
{
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.Net.HttpListener/tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

[assembly: SkipOnMono("System.Net.HttpListener is not supported on wasm", TestPlatforms.Browser)]
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StringResourcesPath>../src/Resources/Strings.resx</StringResourcesPath>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="GetContextHelper.cs" />
<Compile Include="HttpListenerFactory.cs" />
<Compile Include="HttpListenerAuthenticationTests.cs" />
Expand Down