3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
- using System . Net . WebSockets ;
7
6
using System . Security . Claims ;
8
7
using System . Threading ;
9
- using System . Threading . Tasks ;
10
8
using Microsoft . AspNet . FeatureModel ;
11
9
using Microsoft . AspNet . Http . Authentication ;
12
10
using Microsoft . AspNet . Http . Collections ;
13
11
using Microsoft . AspNet . Http . Infrastructure ;
14
- using Microsoft . Net . Http . Headers ;
15
12
16
13
namespace Microsoft . AspNet . Http
17
14
{
18
15
public class DefaultHttpContext : HttpContext
19
16
{
20
- private static IList < string > EmptyList = new List < string > ( ) ;
21
-
22
17
private readonly HttpRequest _request ;
23
18
private readonly HttpResponse _response ;
24
19
private readonly ConnectionInfo _connection ;
@@ -28,8 +23,8 @@ public class DefaultHttpContext : HttpContext
28
23
private FeatureReference < IServiceProvidersFeature > _serviceProviders ;
29
24
private FeatureReference < IHttpAuthenticationFeature > _authentication ;
30
25
private FeatureReference < IHttpRequestLifetimeFeature > _lifetime ;
31
- private FeatureReference < IHttpWebSocketFeature > _webSockets ;
32
26
private FeatureReference < ISessionFeature > _session ;
27
+ private WebSocketManager _websockets ;
33
28
private IFeatureCollection _features ;
34
29
35
30
public DefaultHttpContext ( )
@@ -51,7 +46,6 @@ public DefaultHttpContext(IFeatureCollection features)
51
46
_serviceProviders = FeatureReference < IServiceProvidersFeature > . Default ;
52
47
_authentication = FeatureReference < IHttpAuthenticationFeature > . Default ;
53
48
_lifetime = FeatureReference < IHttpRequestLifetimeFeature > . Default ;
54
- _webSockets = FeatureReference < IHttpWebSocketFeature > . Default ;
55
49
_session = FeatureReference < ISessionFeature > . Default ;
56
50
}
57
51
@@ -75,11 +69,6 @@ private IHttpRequestLifetimeFeature LifetimeFeature
75
69
get { return _lifetime . Fetch ( _features ) ; }
76
70
}
77
71
78
- private IHttpWebSocketFeature WebSocketFeature
79
- {
80
- get { return _webSockets . Fetch ( _features ) ; }
81
- }
82
-
83
72
private ISessionFeature SessionFeature
84
73
{
85
74
get { return _session . Fetch ( _features ) ; }
@@ -161,20 +150,15 @@ public override ISessionCollection Session
161
150
}
162
151
}
163
152
164
- public override bool IsWebSocketRequest
153
+ public override WebSocketManager WebSockets
165
154
{
166
155
get
167
156
{
168
- var webSocketFeature = WebSocketFeature ;
169
- return webSocketFeature != null && webSocketFeature . IsWebSocketRequest ;
170
- }
171
- }
172
-
173
- public override IList < string > WebSocketRequestedProtocols
174
- {
175
- get
176
- {
177
- return Request . Headers . GetValues ( HeaderNames . WebSocketSubProtocols ) ?? EmptyList ;
157
+ if ( _websockets == null )
158
+ {
159
+ _websockets = new DefaultWebSocketManager ( _features ) ;
160
+ }
161
+ return _websockets ;
178
162
}
179
163
}
180
164
@@ -203,15 +187,5 @@ public override void SetFeature(Type type, object instance)
203
187
{
204
188
_features [ type ] = instance ;
205
189
}
206
-
207
- public override Task < WebSocket > AcceptWebSocketAsync ( string subProtocol )
208
- {
209
- var webSocketFeature = WebSocketFeature ;
210
- if ( WebSocketFeature == null )
211
- {
212
- throw new NotSupportedException ( "WebSockets are not supported" ) ;
213
- }
214
- return WebSocketFeature . AcceptAsync ( new WebSocketAcceptContext ( ) { SubProtocol = subProtocol } ) ;
215
- }
216
190
}
217
191
}
0 commit comments