Skip to content

Commit 9b93036

Browse files
authored
Fix #46123 - make the subProtocol nullable for HttpListenerContext::AcceptWebSocketAsync (#47402)
* Fix #46123 - make `subProtocol` nullable when dealing with WebSockets in HttpListener. * Update ref for System.Net.HttpListener
1 parent a1f137e commit 9b93036

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ internal HttpListenerContext() { }
4545
public System.Net.HttpListenerRequest Request { get { throw null; } }
4646
public System.Net.HttpListenerResponse Response { get { throw null; } }
4747
public System.Security.Principal.IPrincipal? User { get { throw null; } }
48-
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol) { throw null; }
49-
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, System.TimeSpan keepAliveInterval) { throw null; }
50-
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, System.TimeSpan keepAliveInterval, System.ArraySegment<byte> internalBuffer) { throw null; }
51-
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, System.TimeSpan keepAliveInterval) { throw null; }
48+
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol) { throw null; }
49+
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, System.TimeSpan keepAliveInterval) { throw null; }
50+
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, System.TimeSpan keepAliveInterval, System.ArraySegment<byte> internalBuffer) { throw null; }
51+
public System.Threading.Tasks.Task<System.Net.WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, System.TimeSpan keepAliveInterval) { throw null; }
5252
}
5353
public partial class HttpListenerException : System.ComponentModel.Win32Exception
5454
{

src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public HttpListenerResponse Response
3333
}
3434
}
3535

36-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol)
36+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol)
3737
{
3838
return AcceptWebSocketAsync(subProtocol, HttpWebSocket.DefaultReceiveBufferSize, WebSocket.DefaultKeepAliveInterval);
3939
}
4040

41-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, TimeSpan keepAliveInterval)
41+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, TimeSpan keepAliveInterval)
4242
{
4343
return AcceptWebSocketAsync(subProtocol, HttpWebSocket.DefaultReceiveBufferSize, keepAliveInterval);
4444
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ internal static bool TryParseBasicAuth(string headerValue, out HttpStatusCode er
8686
}
8787
}
8888

89-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
89+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
9090
{
9191
return HttpWebSocket.AcceptWebSocketAsyncCore(this, subProtocol, receiveBufferSize, keepAliveInterval);
9292
}
9393

9494
[EditorBrowsable(EditorBrowsableState.Never)]
95-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer)
95+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer)
9696
{
9797
WebSocketValidate.ValidateArraySegment(internalBuffer, nameof(internalBuffer));
9898
HttpWebSocket.ValidateOptions(subProtocol, receiveBufferSize, HttpWebSocket.MinSendBufferSize, keepAliveInterval);

src/libraries/System.Net.HttpListener/src/System/Net/Managed/WebSockets/HttpWebSocket.Managed.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static partial class HttpWebSocket
1010
private const string SupportedVersion = "13";
1111

1212
internal static async Task<HttpListenerWebSocketContext> AcceptWebSocketAsyncCore(HttpListenerContext context,
13-
string subProtocol,
13+
string? subProtocol,
1414
int receiveBufferSize,
1515
TimeSpan keepAliveInterval,
1616
ArraySegment<byte>? internalBuffer = null)

src/libraries/System.Net.HttpListener/src/System/Net/WebSockets/HttpWebSocket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static string GetSecWebSocketAcceptString(string? secWebSocketKey)
2828

2929
// return value here signifies if a Sec-WebSocket-Protocol header should be returned by the server.
3030
internal static bool ProcessWebSocketProtocolHeader(string? clientSecWebSocketProtocol,
31-
string subProtocol,
31+
string? subProtocol,
3232
out string acceptProtocol)
3333
{
3434
acceptProtocol = string.Empty;
@@ -76,7 +76,7 @@ internal static bool ProcessWebSocketProtocolHeader(string? clientSecWebSocketPr
7676
subProtocol));
7777
}
7878

79-
internal static void ValidateOptions(string subProtocol, int receiveBufferSize, int sendBufferSize, TimeSpan keepAliveInterval)
79+
internal static void ValidateOptions(string? subProtocol, int receiveBufferSize, int sendBufferSize, TimeSpan keepAliveInterval)
8080
{
8181
if (subProtocol != null)
8282
{

src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerContext.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal void SetIdentity(IPrincipal principal, string? mutualAuthentication)
4848

4949
internal ulong RequestId => Request.RequestId;
5050

51-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol,
51+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol,
5252
int receiveBufferSize,
5353
TimeSpan keepAliveInterval)
5454
{
@@ -62,7 +62,7 @@ public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtoco
6262
}
6363

6464
[EditorBrowsable(EditorBrowsableState.Never)]
65-
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol,
65+
public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol,
6666
int receiveBufferSize,
6767
TimeSpan keepAliveInterval,
6868
ArraySegment<byte> internalBuffer)

src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/HttpWebSocket.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace System.Net.WebSockets
1515
internal static partial class HttpWebSocket
1616
{
1717
internal static Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(HttpListenerContext context,
18-
string subProtocol,
18+
string? subProtocol,
1919
int receiveBufferSize,
2020
TimeSpan keepAliveInterval,
2121
ArraySegment<byte> internalBuffer)
@@ -28,7 +28,7 @@ internal static Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(HttpList
2828
}
2929

3030
private static async Task<HttpListenerWebSocketContext> AcceptWebSocketAsyncCore(HttpListenerContext context,
31-
string subProtocol,
31+
string? subProtocol,
3232
int receiveBufferSize,
3333
TimeSpan keepAliveInterval,
3434
ArraySegment<byte> internalBuffer)

src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/ServerWebSocket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace System.Net.WebSockets
1010
internal sealed class ServerWebSocket : WebSocketBase
1111
{
1212
internal static WebSocket Create(Stream innerStream,
13-
string subProtocol,
13+
string? subProtocol,
1414
int receiveBufferSize,
1515
TimeSpan keepAliveInterval,
1616
ArraySegment<byte> internalBuffer)
@@ -37,7 +37,7 @@ internal static WebSocket Create(Stream innerStream,
3737
private readonly Interop.WebSocket.Property[] _properties;
3838

3939
public ServerWebSocket(Stream innerStream,
40-
string subProtocol,
40+
string? subProtocol,
4141
int receiveBufferSize,
4242
TimeSpan keepAliveInterval,
4343
ArraySegment<byte> internalBuffer)

src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal abstract class WebSocketBase : WebSocket, IDisposable
2222
private readonly OutstandingOperationHelper _sendOutstandingOperationHelper;
2323
private readonly Stream _innerStream;
2424
private readonly IWebSocketStream? _innerStreamAsWebSocketStream;
25-
private readonly string _subProtocol;
25+
private readonly string? _subProtocol;
2626

2727
// We are not calling Dispose method on this object in Cleanup method to avoid a race condition while one thread is calling disposing on
2828
// this object and another one is still using WaitAsync. According to Dev11 358715, this should be fine as long as we are not accessing the
@@ -54,7 +54,7 @@ internal abstract class WebSocketBase : WebSocket, IDisposable
5454
private Exception? _pendingException;
5555

5656
protected WebSocketBase(Stream innerStream,
57-
string subProtocol,
57+
string? subProtocol,
5858
TimeSpan keepAliveInterval,
5959
WebSocketBuffer internalBuffer)
6060
{
@@ -113,7 +113,7 @@ public override WebSocketState State
113113
}
114114
}
115115

116-
public override string SubProtocol
116+
public override string? SubProtocol
117117
{
118118
get
119119
{

0 commit comments

Comments
 (0)