@@ -1015,6 +1015,9 @@ private bool doHandshake ()
10151015 if ( _protocols != null )
10161016 _protocol = res . Headers [ "Sec-WebSocket-Protocol" ] ;
10171017
1018+ if ( ExtensionsRequested )
1019+ processSecWebSocketExtensionsServerHeader ( res . Headers [ "Sec-WebSocket-Extensions" ] ) ;
1020+
10181021 var cookies = res . Cookies ;
10191022 if ( cookies . Count > 0 )
10201023 _cookies . SetOrRemove ( cookies ) ;
@@ -1689,20 +1692,19 @@ private bool validateSecWebSocketAcceptHeader (string value)
16891692 // As client
16901693 private bool validateSecWebSocketExtensionsHeader ( string value )
16911694 {
1692- var comp = _compression != CompressionMethod . None ;
1693- if ( value == null || value . Length == 0 ) {
1694- if ( comp )
1695- _compression = CompressionMethod . None ;
1696-
1695+ if ( value == null )
16971696 return true ;
1698- }
16991697
1700- if ( ! comp )
1698+ if ( value . Length == 0 )
1699+ return false ;
1700+
1701+ if ( ! ExtensionsRequested )
17011702 return false ;
17021703
1704+ var comp = _compression != CompressionMethod . None ;
17031705 foreach ( var e in value . SplitHeaderValue ( ',' ) ) {
17041706 var ext = e . Trim ( ) ;
1705- if ( ext . IsCompressionExtension ( _compression ) ) {
1707+ if ( comp && ext . IsCompressionExtension ( _compression ) ) {
17061708 if ( ! ext . Contains ( "server_no_context_takeover" ) ) {
17071709 _logger . Error ( "The server hasn't sent back 'server_no_context_takeover'." ) ;
17081710 return false ;
@@ -1712,13 +1714,15 @@ private bool validateSecWebSocketExtensionsHeader (string value)
17121714 _logger . Warn ( "The server hasn't sent back 'client_no_context_takeover'." ) ;
17131715
17141716 var method = _compression . ToExtensionString ( ) ;
1715- var invalid = ext . SplitHeaderValue ( ';' ) . Contains (
1716- t => {
1717- t = t . Trim ( ) ;
1718- return t != method &&
1719- t != "server_no_context_takeover" &&
1720- t != "client_no_context_takeover" ;
1721- } ) ;
1717+ var invalid =
1718+ ext . SplitHeaderValue ( ';' ) . Contains (
1719+ t => {
1720+ t = t . Trim ( ) ;
1721+ return t != method
1722+ && t != "server_no_context_takeover"
1723+ && t != "client_no_context_takeover" ;
1724+ }
1725+ ) ;
17221726
17231727 if ( invalid )
17241728 return false ;
@@ -1728,7 +1732,6 @@ private bool validateSecWebSocketExtensionsHeader (string value)
17281732 }
17291733 }
17301734
1731- _extensions = value ;
17321735 return true ;
17331736 }
17341737
0 commit comments