|
4 | 4 | using System;
|
5 | 5 | using System.Diagnostics;
|
6 | 6 | using System.IO;
|
7 |
| -using System.Net.WebSockets; |
8 | 7 | using System.Security.Authentication.ExtendedProtection;
|
9 | 8 | using System.Security.Claims;
|
10 | 9 | using System.Threading;
|
@@ -110,155 +109,6 @@ public Task<Stream> UpgradeAsync()
|
110 | 109 | return Task.FromResult<Stream>(opaqueStream);
|
111 | 110 | }
|
112 | 111 |
|
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 |
| - |
262 | 112 | // TODO: Public when needed
|
263 | 113 | internal bool TryGetChannelBinding(ref ChannelBinding value)
|
264 | 114 | {
|
|
0 commit comments