1111 using Swan ;
1212#if NET47
1313 using System . Net . WebSockets ;
14+ using System . Text . RegularExpressions ;
1415#else
1516 using Net ;
1617#endif
@@ -28,13 +29,25 @@ public class WebSocketsModule : WebModuleBase
2829 private readonly Dictionary < string , WebSocketsServer > _serverMap =
2930 new Dictionary < string , WebSocketsServer > ( StringComparer . OrdinalIgnoreCase ) ;
3031
32+ #if NETSTANDARD2_0
33+ private readonly Regex splitter = new Regex ( @"(\s|[,;])+" ) ;
34+ #endif
35+
3136 /// <summary>
3237 /// Initializes a new instance of the <see cref="WebSocketsModule"/> class.
3338 /// </summary>
3439 public WebSocketsModule ( )
3540 {
3641 AddHandler ( ModuleMap . AnyPath , HttpVerbs . Any , async ( context , ct ) =>
3742 {
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+
3851 // check if it is a WebSocket request (this only works with Win8 and Windows 2012)
3952 if ( context . Request . IsWebSocketRequest == false )
4053 return false ;
@@ -59,7 +72,7 @@ public WebSocketsModule()
5972 /// The name.
6073 /// </value>
6174 public override string Name => nameof ( WebSocketsModule ) . Humanize ( ) ;
62-
75+
6376 /// <summary>
6477 /// Registers the web sockets server given a WebSocketsServer Type.
6578 /// </summary>
@@ -93,7 +106,7 @@ public void RegisterWebSocketsServer(Type socketType)
93106 nameof ( socketType ) ) ;
94107 }
95108
96- _serverMap [ attribute . Path ] = ( WebSocketsServer ) Activator . CreateInstance ( socketType ) ;
109+ _serverMap [ attribute . Path ] = ( WebSocketsServer ) Activator . CreateInstance ( socketType ) ;
97110 }
98111
99112 /// <summary>
@@ -196,7 +209,7 @@ public ReadOnlyCollection<WebSocketContext> WebSockets
196209 /// The name of the server.
197210 /// </value>
198211 public abstract string ServerName { get ; }
199-
212+
200213 /// <summary>
201214 /// Gets the Encoding used to use the Send method to send a string. The default is UTF8 per the WebSocket specification.
202215 /// </summary>
@@ -258,7 +271,7 @@ await context.AcceptWebSocketAsync(
258271 try
259272 {
260273#if NET47
261- // define a receive buffer
274+ // define a receive buffer
262275 var receiveBuffer = new byte [ receiveBufferSize ] ;
263276
264277 // define a dynamic buffer that holds multi-part receptions
@@ -472,9 +485,9 @@ protected abstract void OnFrameReceived(
472485 /// </summary>
473486 /// <param name="context">The context.</param>
474487 /// <param name="localEndPoint">The local endpoint.</param>
475- /// /// <param name="remoteEndPoint">The remote endpoint.</param>
488+ /// <param name="remoteEndPoint">The remote endpoint.</param>
476489 protected abstract void OnClientConnected (
477- WebSocketContext context ,
490+ WebSocketContext context ,
478491 System . Net . IPEndPoint localEndPoint ,
479492 System . Net . IPEndPoint remoteEndPoint ) ;
480493#else
0 commit comments