11
11
using Swan ;
12
12
#if NET47
13
13
using System . Net . WebSockets ;
14
+ using System . Text . RegularExpressions ;
14
15
#else
15
16
using Net ;
16
17
#endif
@@ -28,13 +29,25 @@ public class WebSocketsModule : WebModuleBase
28
29
private readonly Dictionary < string , WebSocketsServer > _serverMap =
29
30
new Dictionary < string , WebSocketsServer > ( StringComparer . OrdinalIgnoreCase ) ;
30
31
32
+ #if NETSTANDARD2_0
33
+ private readonly Regex splitter = new Regex ( @"(\s|[,;])+" ) ;
34
+ #endif
35
+
31
36
/// <summary>
32
37
/// Initializes a new instance of the <see cref="WebSocketsModule"/> class.
33
38
/// </summary>
34
39
public WebSocketsModule ( )
35
40
{
36
41
AddHandler ( ModuleMap . AnyPath , HttpVerbs . Any , async ( context , ct ) =>
37
42
{
43
+ #if NETSTANDARD2_0
44
+ // Support for Firefox https://github.com/dotnet/corefx/issues/24550#issuecomment-338048691
45
+ var connectionValues = context . Request . Headers . GetValues ( "Connection" ) ;
46
+ context . Request . Headers . Remove ( "Connection" ) ;
47
+ var headers = connectionValues . Select ( tk => splitter . Split ( tk ) ) . First ( ) ;
48
+ headers . ToList ( ) . ForEach ( value => context . Request . Headers . Add ( "Connection" , value ) ) ;
49
+ #endif
50
+
38
51
// check if it is a WebSocket request (this only works with Win8 and Windows 2012)
39
52
if ( context . Request . IsWebSocketRequest == false )
40
53
return false ;
@@ -59,7 +72,7 @@ public WebSocketsModule()
59
72
/// The name.
60
73
/// </value>
61
74
public override string Name => nameof ( WebSocketsModule ) . Humanize ( ) ;
62
-
75
+
63
76
/// <summary>
64
77
/// Registers the web sockets server given a WebSocketsServer Type.
65
78
/// </summary>
@@ -93,7 +106,7 @@ public void RegisterWebSocketsServer(Type socketType)
93
106
nameof ( socketType ) ) ;
94
107
}
95
108
96
- _serverMap [ attribute . Path ] = ( WebSocketsServer ) Activator . CreateInstance ( socketType ) ;
109
+ _serverMap [ attribute . Path ] = ( WebSocketsServer ) Activator . CreateInstance ( socketType ) ;
97
110
}
98
111
99
112
/// <summary>
@@ -196,7 +209,7 @@ public ReadOnlyCollection<WebSocketContext> WebSockets
196
209
/// The name of the server.
197
210
/// </value>
198
211
public abstract string ServerName { get ; }
199
-
212
+
200
213
/// <summary>
201
214
/// Gets the Encoding used to use the Send method to send a string. The default is UTF8 per the WebSocket specification.
202
215
/// </summary>
@@ -258,7 +271,7 @@ await context.AcceptWebSocketAsync(
258
271
try
259
272
{
260
273
#if NET47
261
- // define a receive buffer
274
+ // define a receive buffer
262
275
var receiveBuffer = new byte [ receiveBufferSize ] ;
263
276
264
277
// define a dynamic buffer that holds multi-part receptions
@@ -472,9 +485,9 @@ protected abstract void OnFrameReceived(
472
485
/// </summary>
473
486
/// <param name="context">The context.</param>
474
487
/// <param name="localEndPoint">The local endpoint.</param>
475
- /// /// <param name="remoteEndPoint">The remote endpoint.</param>
488
+ /// <param name="remoteEndPoint">The remote endpoint.</param>
476
489
protected abstract void OnClientConnected (
477
- WebSocketContext context ,
490
+ WebSocketContext context ,
478
491
System . Net . IPEndPoint localEndPoint ,
479
492
System . Net . IPEndPoint remoteEndPoint ) ;
480
493
#else
0 commit comments