@@ -34,7 +34,7 @@ internal static class HandshakeHelpers
34
34
} ;
35
35
36
36
// 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 )
38
38
{
39
39
bool validUpgrade = false , validConnection = false , validKey = false , validVersion = false ;
40
40
@@ -43,11 +43,11 @@ public static bool CheckSupportedWebSocketRequest(string method, List<KeyValuePa
43
43
return false ;
44
44
}
45
45
46
- foreach ( var pair in headers )
46
+ foreach ( var pair in interestingHeaders )
47
47
{
48
48
if ( string . Equals ( HeaderNames . Connection , pair . Key , StringComparison . OrdinalIgnoreCase ) )
49
49
{
50
- if ( string . Equals ( Constants . Headers . ConnectionUpgrade , pair . Value , StringComparison . OrdinalIgnoreCase ) )
50
+ if ( string . Equals ( HeaderNames . Upgrade , pair . Value , StringComparison . OrdinalIgnoreCase ) )
51
51
{
52
52
validConnection = true ;
53
53
}
@@ -72,12 +72,26 @@ public static bool CheckSupportedWebSocketRequest(string method, List<KeyValuePa
72
72
}
73
73
}
74
74
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
+
75
89
return validConnection && validUpgrade && validVersion && validKey ;
76
90
}
77
91
78
92
public static void GenerateResponseHeaders ( string key , string ? subProtocol , IHeaderDictionary headers )
79
93
{
80
- headers [ HeaderNames . Connection ] = Constants . Headers . ConnectionUpgrade ;
94
+ headers [ HeaderNames . Connection ] = HeaderNames . Upgrade ;
81
95
headers [ HeaderNames . Upgrade ] = Constants . Headers . UpgradeWebSocket ;
82
96
headers [ HeaderNames . SecWebSocketAccept ] = CreateResponseKey ( key ) ;
83
97
if ( ! string . IsNullOrWhiteSpace ( subProtocol ) )
0 commit comments