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

Obsolete ServicePointManager 🎉 #103456

Merged
merged 2 commits into from
Jun 15, 2024
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
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Net/TlsStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using System.Threading;
using System.Threading.Tasks;

#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete
// This type is used by FtpWebRequest (already obsolete) and SmtpClient (discouraged).

namespace System.Net
{
internal sealed class TlsStream : NetworkStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Security;
Expand Down Expand Up @@ -100,7 +101,11 @@ public HttpConnection(Socket sock, HttpEndPointListener epl, bool secure, X509Ce
}

_timer = new Timer(OnTimeout, null, Timeout.Infinite, Timeout.Infinite);

#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete
_sslStream?.AuthenticateAsServer(_cert, true, (SslProtocols)ServicePointManager.SecurityProtocol, false);
#pragma warning restore SYSLIB0014
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SslStream part of this logic is currently unreachable - tracked by #19752

if (secure)
{
_secure = secure;
_cert = HttpListener.LoadCertificateAndKey(addr, port);
}

internal static X509Certificate? LoadCertificateAndKey(IPAddress addr, int port)
{
// TODO https://github.com/dotnet/runtime/issues/19752: Implement functionality to read SSL certificate.
return null;
}

if (_secure && _cert == null)
{
accepted.Close();
return;
}


Init();
}

Expand Down
4 changes: 1 addition & 3 deletions src/libraries/System.Net.Requests/ref/System.Net.Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ internal ServicePoint() { }
public bool CloseConnectionGroup(string connectionGroupName) { throw null; }
public void SetTcpKeepAlive(bool enabled, int keepAliveTime, int keepAliveInterval) { }
}
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
MihaZupan marked this conversation as resolved.
Show resolved Hide resolved
public partial class ServicePointManager
{
internal ServicePointManager() { }
Expand All @@ -504,11 +505,8 @@ internal ServicePointManager() { }
public static System.Net.SecurityProtocolType SecurityProtocol { get { throw null; } set { } }
public static System.Net.Security.RemoteCertificateValidationCallback? ServerCertificateValidationCallback { get { throw null; } set { } }
public static bool UseNagleAlgorithm { get { throw null; } set { } }
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy) { throw null; }
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(System.Uri address) { throw null; }
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(System.Uri address, System.Net.IWebProxy? proxy) { throw null; }
public static void SetTcpKeepAlive(bool enabled, int keepAliveTime, int keepAliveInterval) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace System.Net
{
// NOTE: While this class is not explicitly marked as obsolete,
// it effectively is by virtue of WebRequest.Create being obsolete.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why haven't we explicitly marked it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was to reduce the noise for anyone still using it without suppressing it at the project level.
They must suppress the warning at least once when creating the request, but not everywhere else they might have plumbed the types through.

public class FileWebRequest : WebRequest, ISerializable
{
private readonly WebHeaderCollection _headers = new WebHeaderCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ internal static FtpMethodInfo GetMethodInfo(string method)
};
}

// NOTE: While this class is not explicitly marked as obsolete,
// it effectively is by virtue of WebRequest.Create being obsolete.

/// <summary>
/// The FtpWebRequest class implements a basic FTP client interface.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace System.Net
{
public delegate void HttpContinueDelegate(int StatusCode, WebHeaderCollection httpHeaders);

// NOTE: While this class is not explicitly marked as obsolete,
// it effectively is by virtue of WebRequest.Create being obsolete.
public class HttpWebRequest : WebRequest, ISerializable
{
private const int DefaultContinueTimeout = 350; // Current default value from .NET Desktop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace System.Net
{
// NOTE: While this class is not explicitly marked as obsolete,
// it effectively is by virtue of ServicePointManager being obsolete,
// where ServicePointManager is the only way to obtain ServicePoint instances.
public class ServicePoint
{
private int _connectionLeaseTimeout = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace System.Net
{
[Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public class ServicePointManager
{
public const int DefaultNonPersistentConnectionLimit = 4;
Expand Down Expand Up @@ -99,13 +100,10 @@ public static int DnsRefreshTimeout
[UnsupportedOSPlatform("browser")]
public static EncryptionPolicy EncryptionPolicy { get; } = EncryptionPolicy.RequireEncryption;

[Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static ServicePoint FindServicePoint(Uri address) => FindServicePoint(address, null);

[Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static ServicePoint FindServicePoint(string uriString, IWebProxy? proxy) => FindServicePoint(new Uri(uriString), proxy);

[Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public static ServicePoint FindServicePoint(Uri address, IWebProxy? proxy)
{
ArgumentNullException.ThrowIfNull(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System.Threading.Tasks;
namespace System.Net
{
// NOTE: While this class is not explicitly marked as obsolete,
// it effectively is by virtue of WebRequest.Create being obsolete.
public abstract class WebRequest : MarshalByRefObject, ISerializable
{
internal sealed class WebRequestPrefixElement
Expand Down
Loading