Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 691c69f

Browse files
committed
#283 remove direct WebSocket support
1 parent 09c993e commit 691c69f

File tree

11 files changed

+0
-2195
lines changed

11 files changed

+0
-2195
lines changed

scripts/UpdateCoreFxCode.ps1

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Microsoft.AspNetCore.Server.HttpSys/FeatureContext.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Globalization;
77
using System.IO;
88
using System.Net;
9-
using System.Net.WebSockets;
109
using System.Security.Claims;
1110
using System.Security.Cryptography.X509Certificates;
1211
using System.Threading;
@@ -28,7 +27,6 @@ internal class FeatureContext :
2827
// ITlsTokenBindingFeature, TODO: https://github.com/aspnet/WebListener/issues/231
2928
IHttpBufferingFeature,
3029
IHttpRequestLifetimeFeature,
31-
IHttpWebSocketFeature,
3230
IHttpAuthenticationFeature,
3331
IHttpUpgradeFeature,
3432
IHttpRequestIdentifierFeature
@@ -442,21 +440,6 @@ async Task<Stream> IHttpUpgradeFeature.UpgradeAsync()
442440
return await _requestContext.UpgradeAsync();
443441
}
444442

445-
bool IHttpWebSocketFeature.IsWebSocketRequest => _requestContext.IsWebSocketRequest;
446-
447-
async Task<WebSocket> IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context)
448-
{
449-
// TODO: Advanced params
450-
string subProtocol = null;
451-
if (context != null)
452-
{
453-
subProtocol = context.SubProtocol;
454-
}
455-
456-
await OnStart();
457-
return await _requestContext.AcceptWebSocketAsync(subProtocol);
458-
}
459-
460443
ClaimsPrincipal IHttpAuthenticationFeature.User
461444
{
462445
get { return _user; }

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/RequestContext.cs

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Diagnostics;
66
using System.IO;
7-
using System.Net.WebSockets;
87
using System.Security.Authentication.ExtendedProtection;
98
using System.Security.Claims;
109
using System.Threading;
@@ -110,155 +109,6 @@ public Task<Stream> UpgradeAsync()
110109
return Task.FromResult<Stream>(opaqueStream);
111110
}
112111

113-
// Compare ValidateWebSocketRequest
114-
public bool IsWebSocketRequest
115-
{
116-
get
117-
{
118-
if (!WebSocketHelpers.AreWebSocketsSupported)
119-
{
120-
return false;
121-
}
122-
123-
if (!IsUpgradableRequest)
124-
{
125-
return false;
126-
}
127-
128-
if (Request.KnownMethod != HttpApi.HTTP_VERB.HttpVerbGET)
129-
{
130-
return false;
131-
}
132-
133-
// Connection: Upgrade (some odd clients send Upgrade,KeepAlive)
134-
var connection = Request.Headers[HttpKnownHeaderNames.Connection].ToString();
135-
if (connection == null || connection.IndexOf(HttpKnownHeaderNames.Upgrade, StringComparison.OrdinalIgnoreCase) < 0)
136-
{
137-
return false;
138-
}
139-
140-
// Upgrade: websocket
141-
var upgrade = Request.Headers[HttpKnownHeaderNames.Upgrade];
142-
if (!string.Equals(WebSocketHelpers.WebSocketUpgradeToken, upgrade, StringComparison.OrdinalIgnoreCase))
143-
{
144-
return false;
145-
}
146-
147-
// Sec-WebSocket-Version: 13
148-
var version = Request.Headers[HttpKnownHeaderNames.SecWebSocketVersion];
149-
if (!string.Equals(WebSocketHelpers.SupportedProtocolVersion, version, StringComparison.OrdinalIgnoreCase))
150-
{
151-
return false;
152-
}
153-
154-
// Sec-WebSocket-Key: {base64string}
155-
var key = Request.Headers[HttpKnownHeaderNames.SecWebSocketKey];
156-
if (!WebSocketHelpers.IsValidWebSocketKey(key))
157-
{
158-
return false;
159-
}
160-
161-
return true;
162-
}
163-
}
164-
165-
// Compare IsWebSocketRequest()
166-
private void ValidateWebSocketRequest()
167-
{
168-
if (!WebSocketHelpers.AreWebSocketsSupported)
169-
{
170-
throw new NotSupportedException("WebSockets are not supported on this platform.");
171-
}
172-
173-
if (!IsUpgradableRequest)
174-
{
175-
throw new InvalidOperationException("This request is not a valid upgrade request.");
176-
}
177-
178-
if (Request.KnownMethod != HttpApi.HTTP_VERB.HttpVerbGET)
179-
{
180-
throw new InvalidOperationException("This request is not a valid upgrade request; invalid verb: " + Request.Method);
181-
}
182-
183-
// Connection: Upgrade (some odd clients send Upgrade,KeepAlive)
184-
var connection = Request.Headers[HttpKnownHeaderNames.Connection].ToString();
185-
if (connection == null || connection.IndexOf(HttpKnownHeaderNames.Upgrade, StringComparison.OrdinalIgnoreCase) < 0)
186-
{
187-
throw new InvalidOperationException("The Connection header is invalid: " + connection);
188-
}
189-
190-
// Upgrade: websocket
191-
var upgrade = Request.Headers[HttpKnownHeaderNames.Upgrade];
192-
if (!string.Equals(WebSocketHelpers.WebSocketUpgradeToken, upgrade, StringComparison.OrdinalIgnoreCase))
193-
{
194-
throw new InvalidOperationException("The Upgrade header is invalid: " + upgrade);
195-
}
196-
197-
// Sec-WebSocket-Version: 13
198-
var version = Request.Headers[HttpKnownHeaderNames.SecWebSocketVersion];
199-
if (!string.Equals(WebSocketHelpers.SupportedProtocolVersion, version, StringComparison.OrdinalIgnoreCase))
200-
{
201-
throw new InvalidOperationException("The Sec-WebSocket-Version header is invalid or not supported: " + version);
202-
}
203-
204-
// Sec-WebSocket-Key: {base64string}
205-
var key = Request.Headers[HttpKnownHeaderNames.SecWebSocketKey];
206-
if (!WebSocketHelpers.IsValidWebSocketKey(key))
207-
{
208-
throw new InvalidOperationException("The Sec-WebSocket-Key header is invalid: " + upgrade);
209-
}
210-
}
211-
212-
public Task<WebSocket> AcceptWebSocketAsync()
213-
{
214-
return AcceptWebSocketAsync(null, WebSocketHelpers.DefaultReceiveBufferSize, WebSocketHelpers.DefaultKeepAliveInterval);
215-
}
216-
217-
public Task<WebSocket> AcceptWebSocketAsync(string subProtocol)
218-
{
219-
return AcceptWebSocketAsync(subProtocol, WebSocketHelpers.DefaultReceiveBufferSize, WebSocketHelpers.DefaultKeepAliveInterval);
220-
}
221-
222-
public Task<WebSocket> AcceptWebSocketAsync(string subProtocol, TimeSpan keepAliveInterval)
223-
{
224-
return AcceptWebSocketAsync(subProtocol, WebSocketHelpers.DefaultReceiveBufferSize, keepAliveInterval);
225-
}
226-
227-
public Task<WebSocket> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
228-
{
229-
if (!IsUpgradableRequest)
230-
{
231-
throw new InvalidOperationException("This request cannot be upgraded.");
232-
}
233-
WebSocketHelpers.ValidateOptions(subProtocol, keepAliveInterval);
234-
235-
return AcceptWebSocketAsyncCore(subProtocol, receiveBufferSize, keepAliveInterval);
236-
}
237-
238-
private async Task<WebSocket> AcceptWebSocketAsyncCore(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
239-
{
240-
ValidateWebSocketRequest();
241-
242-
var subProtocols = Request.Headers.GetValues(HttpKnownHeaderNames.SecWebSocketProtocol);
243-
var shouldSendSecWebSocketProtocolHeader = WebSocketHelpers.ProcessWebSocketProtocolHeader(subProtocols, subProtocol);
244-
if (shouldSendSecWebSocketProtocolHeader)
245-
{
246-
Response.Headers[HttpKnownHeaderNames.SecWebSocketProtocol] = subProtocol;
247-
}
248-
249-
// negotiate the websocket key return value
250-
var secWebSocketKey = Request.Headers[HttpKnownHeaderNames.SecWebSocketKey];
251-
var secWebSocketAccept = WebSocketHelpers.GetSecWebSocketAcceptString(secWebSocketKey);
252-
253-
Response.Headers.Append(HttpKnownHeaderNames.Connection, HttpKnownHeaderNames.Upgrade);
254-
Response.Headers.Append(HttpKnownHeaderNames.Upgrade, WebSocketHelpers.WebSocketUpgradeToken);
255-
Response.Headers.Append(HttpKnownHeaderNames.SecWebSocketAccept, secWebSocketAccept);
256-
257-
var opaqueStream = await UpgradeAsync();
258-
259-
return WebSocketHelpers.CreateServerWebSocket(opaqueStream, subProtocol, receiveBufferSize, keepAliveInterval);
260-
}
261-
262112
// TODO: Public when needed
263113
internal bool TryGetChannelBinding(ref ChannelBinding value)
264114
{

0 commit comments

Comments
 (0)