@@ -34,7 +34,7 @@ internal static class HandshakeHelpers
3434 } ;
3535
3636 // Verify Method, Upgrade, Connection, version, key, etc..
37- public static bool CheckSupportedWebSocketRequest ( string method , List < KeyValuePair < string , string > > headers )
37+ public static bool CheckSupportedWebSocketRequest ( string method , List < KeyValuePair < string , string > > interestingHeaders , IHeaderDictionary requestHeaders )
3838 {
3939 bool validUpgrade = false , validConnection = false , validKey = false , validVersion = false ;
4040
@@ -43,11 +43,11 @@ public static bool CheckSupportedWebSocketRequest(string method, List<KeyValuePa
4343 return false ;
4444 }
4545
46- foreach ( var pair in headers )
46+ foreach ( var pair in interestingHeaders )
4747 {
4848 if ( string . Equals ( HeaderNames . Connection , pair . Key , StringComparison . OrdinalIgnoreCase ) )
4949 {
50- if ( string . Equals ( Constants . Headers . ConnectionUpgrade , pair . Value , StringComparison . OrdinalIgnoreCase ) )
50+ if ( string . Equals ( HeaderNames . Upgrade , pair . Value , StringComparison . OrdinalIgnoreCase ) )
5151 {
5252 validConnection = true ;
5353 }
@@ -72,12 +72,26 @@ public static bool CheckSupportedWebSocketRequest(string method, List<KeyValuePa
7272 }
7373 }
7474
75+ // WebSockets are long lived; so if the header values are valid we switch them out for the interned versions.
76+ if ( validConnection && requestHeaders [ HeaderNames . Connection ] . Count == 1 )
77+ {
78+ requestHeaders [ HeaderNames . Connection ] = HeaderNames . Upgrade ;
79+ }
80+ if ( validUpgrade && requestHeaders [ HeaderNames . Upgrade ] . Count == 1 )
81+ {
82+ requestHeaders [ HeaderNames . Upgrade ] = Constants . Headers . UpgradeWebSocket ;
83+ }
84+ if ( validVersion && requestHeaders [ HeaderNames . SecWebSocketVersion ] . Count == 1 )
85+ {
86+ requestHeaders [ HeaderNames . SecWebSocketVersion ] = Constants . Headers . SupportedVersion ;
87+ }
88+
7589 return validConnection && validUpgrade && validVersion && validKey ;
7690 }
7791
7892 public static void GenerateResponseHeaders ( string key , string ? subProtocol , IHeaderDictionary headers )
7993 {
80- headers [ HeaderNames . Connection ] = Constants . Headers . ConnectionUpgrade ;
94+ headers [ HeaderNames . Connection ] = HeaderNames . Upgrade ;
8195 headers [ HeaderNames . Upgrade ] = Constants . Headers . UpgradeWebSocket ;
8296 headers [ HeaderNames . SecWebSocketAccept ] = CreateResponseKey ( key ) ;
8397 if ( ! string . IsNullOrWhiteSpace ( subProtocol ) )
0 commit comments