@@ -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,62 @@ 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 ( ) {
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 ( config) = _config {
221+ if let Some ( compression) = config. compression {
222+ for ( name, params) in exts {
223+ if name != compression. name ( ) {
224+ return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension (
225+ name. to_string ( ) ,
226+ ) ) ) ;
227+ }
228+
229+ // Already had PMCE configured
230+ if extensions. is_some ( ) {
231+ return Err ( Error :: Protocol ( ProtocolError :: ExtensionConflict (
232+ name. to_string ( ) ,
233+ ) ) ) ;
234+ }
235+
236+ extensions = Some ( Extensions {
237+ compression : Some ( compression. accept_response ( params) ?) ,
238+ } ) ;
239+ }
240+ } else if let Some ( ( name, _) ) = exts. next ( ) {
241+ // The client didn't request anything, but got something
221242 return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension (
222243 name. to_string ( ) ,
223244 ) ) ) ;
224245 }
246+ }
247+ extensions
248+ }
225249
226- // Already had PMCE configured
227- if extensions. is_some ( ) {
228- return Err ( Error :: Protocol ( ProtocolError :: ExtensionConflict (
229- name. to_string ( ) ,
230- ) ) ) ;
231- }
232-
233- extensions = Some ( Extensions {
234- compression : Some ( compression. accept_response ( params) ?) ,
235- } ) ;
250+ #[ cfg( not( feature = "deflate" ) ) ]
251+ {
252+ if let Some ( ( name, _) ) = exts. next ( ) {
253+ // The client didn't request anything, but got something
254+ return Err ( Error :: Protocol ( ProtocolError :: InvalidExtension ( name. to_string ( ) ) ) ) ;
236255 }
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 ( ) ) ) ) ;
256+ None
240257 }
241- }
258+ } else {
259+ None
260+ } ;
242261
243262 // 6. If the response includes a |Sec-WebSocket-Protocol| header field
244263 // and this header field indicates the use of a subprotocol that was
@@ -292,7 +311,9 @@ fn generate_key() -> String {
292311#[ cfg( test) ]
293312mod tests {
294313 use super :: { super :: machine:: TryParse , generate_key, generate_request, Response } ;
295- use crate :: { client:: IntoClientRequest , extensions:: DeflateConfig , protocol:: WebSocketConfig } ;
314+ use crate :: client:: IntoClientRequest ;
315+ #[ cfg( feature = "deflate" ) ]
316+ use crate :: { extensions:: DeflateConfig , protocol:: WebSocketConfig } ;
296317
297318 #[ test]
298319 fn random_keys ( ) {
@@ -361,6 +382,7 @@ mod tests {
361382 assert_eq ! ( & request[ ..] , & correct[ ..] ) ;
362383 }
363384
385+ #[ cfg( feature = "deflate" ) ]
364386 #[ test]
365387 fn request_with_compression ( ) {
366388 let request = "ws://localhost/getCaseCount" . into_client_request ( ) . unwrap ( ) ;
0 commit comments