@@ -17,7 +17,7 @@ use super::{
1717} ;
1818use crate :: {
1919 error:: { Error , ProtocolError , Result , UrlError } ,
20- extensions:: { self , Extensions } ,
20+ extensions:: Extensions ,
2121 protocol:: { Role , WebSocket , WebSocketConfig } ,
2222} ;
2323
@@ -161,7 +161,7 @@ impl VerifyData {
161161 pub fn verify_response (
162162 & self ,
163163 response : Response ,
164- config : & Option < WebSocketConfig > ,
164+ _config : & Option < WebSocketConfig > ,
165165 ) -> Result < ( Response , Option < Extensions > ) > {
166166 // 1. If the status code received from the server is not 101, the
167167 // client handles the response per HTTP [RFC2616] procedures. (RFC 6455)
@@ -202,43 +202,58 @@ impl VerifyData {
202202 if !headers. get ( "Sec-WebSocket-Accept" ) . map ( |h| h == & self . accept_key ) . unwrap_or ( false ) {
203203 return Err ( Error :: Protocol ( ProtocolError :: SecWebSocketAcceptKeyMismatch ) ) ;
204204 }
205- let mut extensions = None ;
206205 // 5. If the response includes a |Sec-WebSocket-Extensions| header
207206 // field and this header field indicates the use of an extension
208207 // that was not present in the client's handshake (the server has
209208 // indicated an extension not requested by the client), the client
210209 // MUST _Fail the WebSocket Connection_. (RFC 6455)
211210 let mut extensions_values = headers. get_all ( "Sec-WebSocket-Extensions" ) . iter ( ) ;
212- if let Some ( value) = extensions_values. next ( ) {
211+ let extensions = if let Some ( value) = extensions_values. next ( ) {
213212 if extensions_values. next ( ) . is_some ( ) {
214213 return Err ( Error :: Protocol ( ProtocolError :: MultipleExtensionsHeaderInResponse ) ) ;
215214 }
216215
217- let mut exts = extensions:: iter_all ( std:: iter:: once ( value) ) ;
218- if let Some ( compression) = & config. and_then ( |c| c. compression ) {
219- for ( name, params) in exts {
220- if name != compression. name ( ) {
221- return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension (
222- name. to_string ( ) ,
223- ) ) ) ;
224- }
225-
226- // Already had PMCE configured
227- if extensions. is_some ( ) {
228- return Err ( Error :: Protocol ( ProtocolError :: ExtensionConflict (
229- name. to_string ( ) ,
230- ) ) ) ;
216+ let mut exts = crate :: extensions:: iter_all ( std:: iter:: once ( value) ) ;
217+ #[ cfg( feature = "deflate" ) ]
218+ {
219+ let mut extensions = None ;
220+ if let Some ( compression) = _config. and_then ( |c| c. compression ) {
221+ for ( name, params) in exts {
222+ if name != compression. name ( ) {
223+ return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension (
224+ name. to_string ( ) ,
225+ ) ) ) ;
226+ }
227+
228+ // Already had PMCE configured
229+ if extensions. is_some ( ) {
230+ return Err ( Error :: Protocol ( ProtocolError :: ExtensionConflict (
231+ name. to_string ( ) ,
232+ ) ) ) ;
233+ }
234+
235+ extensions = Some ( Extensions {
236+ compression : Some ( compression. accept_response ( params) ?) ,
237+ } ) ;
231238 }
239+ } else if let Some ( ( name, _) ) = exts. next ( ) {
240+ // The client didn't request anything, but got something
241+ return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension ( name. to_string ( ) ) ) ) ;
242+ }
243+ extensions
244+ }
232245
233- extensions = Some ( Extensions {
234- compression : Some ( compression. accept_response ( params) ?) ,
235- } ) ;
246+ #[ cfg( not( feature = "deflate" ) ) ]
247+ {
248+ if let Some ( ( name, _) ) = exts. next ( ) {
249+ // The client didn't request anything, but got something
250+ return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension ( name. to_string ( ) ) ) ) ;
236251 }
237- } else if let Some ( ( name, _) ) = exts. next ( ) {
238- // The client didn't request anything, but got something
239- return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension ( name. to_string ( ) ) ) ) ;
252+ None
240253 }
241- }
254+ } else {
255+ None
256+ } ;
242257
243258 // 6. If the response includes a |Sec-WebSocket-Protocol| header field
244259 // and this header field indicates the use of a subprotocol that was
@@ -292,7 +307,9 @@ fn generate_key() -> String {
292307#[ cfg( test) ]
293308mod tests {
294309 use super :: { super :: machine:: TryParse , generate_key, generate_request, Response } ;
295- use crate :: { client:: IntoClientRequest , extensions:: DeflateConfig , protocol:: WebSocketConfig } ;
310+ use crate :: client:: IntoClientRequest ;
311+ #[ cfg( feature = "deflate" ) ]
312+ use crate :: { extensions:: DeflateConfig , protocol:: WebSocketConfig } ;
296313
297314 #[ test]
298315 fn random_keys ( ) {
@@ -361,6 +378,7 @@ mod tests {
361378 assert_eq ! ( & request[ ..] , & correct[ ..] ) ;
362379 }
363380
381+ #[ cfg( feature = "deflate" ) ]
364382 #[ test]
365383 fn request_with_compression ( ) {
366384 let request = "ws://localhost/getCaseCount" . into_client_request ( ) . unwrap ( ) ;
0 commit comments