Skip to content

Commit 4b7fda5

Browse files
authored
Obsolete ServicePointManager 🎉 (#103456)
* Obsolete ServicePointManager * Tweak obsoletion message on ServicePointManager
1 parent f69972f commit 4b7fda5

File tree

9 files changed

+22
-6
lines changed

9 files changed

+22
-6
lines changed

src/libraries/Common/src/System/Net/TlsStream.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010

11+
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete
12+
// This type is used by FtpWebRequest (already obsolete) and SmtpClient (discouraged).
13+
1114
namespace System.Net
1215
{
1316
internal sealed class TlsStream : NetworkStream

src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpConnection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
//
3232

33+
using System.Diagnostics;
3334
using System.Diagnostics.CodeAnalysis;
3435
using System.IO;
3536
using System.Net.Security;
@@ -100,7 +101,11 @@ public HttpConnection(Socket sock, HttpEndPointListener epl, bool secure, X509Ce
100101
}
101102

102103
_timer = new Timer(OnTimeout, null, Timeout.Infinite, Timeout.Infinite);
104+
105+
#pragma warning disable SYSLIB0014 // ServicePointManager is obsolete
103106
_sslStream?.AuthenticateAsServer(_cert, true, (SslProtocols)ServicePointManager.SecurityProtocol, false);
107+
#pragma warning restore SYSLIB0014
108+
104109
Init();
105110
}
106111

src/libraries/System.Net.Requests/ref/System.Net.Requests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ internal ServicePoint() { }
486486
public bool CloseConnectionGroup(string connectionGroupName) { throw null; }
487487
public void SetTcpKeepAlive(bool enabled, int keepAliveTime, int keepAliveInterval) { }
488488
}
489+
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. Settings on ServicePointManager no longer affect SslStream or HttpClient.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
489490
public partial class ServicePointManager
490491
{
491492
internal ServicePointManager() { }
@@ -504,11 +505,8 @@ internal ServicePointManager() { }
504505
public static System.Net.SecurityProtocolType SecurityProtocol { get { throw null; } set { } }
505506
public static System.Net.Security.RemoteCertificateValidationCallback? ServerCertificateValidationCallback { get { throw null; } set { } }
506507
public static bool UseNagleAlgorithm { get { throw null; } set { } }
507-
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
508508
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy) { throw null; }
509-
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
510509
public static System.Net.ServicePoint FindServicePoint(System.Uri address) { throw null; }
511-
[System.ObsoleteAttribute("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
512510
public static System.Net.ServicePoint FindServicePoint(System.Uri address, System.Net.IWebProxy? proxy) { throw null; }
513511
public static void SetTcpKeepAlive(bool enabled, int keepAliveTime, int keepAliveInterval) { }
514512
}

src/libraries/System.Net.Requests/src/System/Net/FileWebRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace System.Net
1111
{
12+
// NOTE: While this class is not explicitly marked as obsolete,
13+
// it effectively is by virtue of WebRequest.Create being obsolete.
1214
public class FileWebRequest : WebRequest, ISerializable
1315
{
1416
private readonly WebHeaderCollection _headers = new WebHeaderCollection();

src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ internal static FtpMethodInfo GetMethodInfo(string method)
176176
};
177177
}
178178

179+
// NOTE: While this class is not explicitly marked as obsolete,
180+
// it effectively is by virtue of WebRequest.Create being obsolete.
181+
179182
/// <summary>
180183
/// The FtpWebRequest class implements a basic FTP client interface.
181184
/// </summary>

src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace System.Net
2626
{
2727
public delegate void HttpContinueDelegate(int StatusCode, WebHeaderCollection httpHeaders);
2828

29+
// NOTE: While this class is not explicitly marked as obsolete,
30+
// it effectively is by virtue of WebRequest.Create being obsolete.
2931
public class HttpWebRequest : WebRequest, ISerializable
3032
{
3133
private const int DefaultContinueTimeout = 350; // Current default value from .NET Desktop.

src/libraries/System.Net.Requests/src/System/Net/ServicePoint/ServicePoint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace System.Net
99
{
10+
// NOTE: While this class is not explicitly marked as obsolete,
11+
// it effectively is by virtue of ServicePointManager being obsolete,
12+
// where ServicePointManager is the only way to obtain ServicePoint instances.
1013
public class ServicePoint
1114
{
1215
private int _connectionLeaseTimeout = -1;

src/libraries/System.Net.Requests/src/System/Net/ServicePoint/ServicePointManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace System.Net
1111
{
12+
[Obsolete(Obsoletions.WebRequestMessage + " Settings on ServicePointManager no longer affect SslStream or HttpClient.", DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
1213
public class ServicePointManager
1314
{
1415
public const int DefaultNonPersistentConnectionLimit = 4;
@@ -99,13 +100,10 @@ public static int DnsRefreshTimeout
99100
[UnsupportedOSPlatform("browser")]
100101
public static EncryptionPolicy EncryptionPolicy { get; } = EncryptionPolicy.RequireEncryption;
101102

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

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

108-
[Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
109107
public static ServicePoint FindServicePoint(Uri address, IWebProxy? proxy)
110108
{
111109
ArgumentNullException.ThrowIfNull(address);

src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using System.Threading.Tasks;
1616
namespace System.Net
1717
{
18+
// NOTE: While this class is not explicitly marked as obsolete,
19+
// it effectively is by virtue of WebRequest.Create being obsolete.
1820
public abstract class WebRequest : MarshalByRefObject, ISerializable
1921
{
2022
internal sealed class WebRequestPrefixElement

0 commit comments

Comments
 (0)