File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -555,23 +555,20 @@ impl WebSocketContext {
555555 debug ! ( "Received close frame: {:?}" , close) ;
556556 match self . state {
557557 WebSocketState :: Active => {
558- let close_code = close. as_ref ( ) . map ( |f| f. code ) ;
559558 self . state = WebSocketState :: ClosedByPeer ;
560- let reply = if let Some ( code) = close_code {
561- if code. is_allowed ( ) {
562- Frame :: close ( Some ( CloseFrame {
563- code : CloseCode :: Normal ,
564- reason : "" . into ( ) ,
565- } ) )
566- } else {
567- Frame :: close ( Some ( CloseFrame {
559+
560+ let close = close. map ( |frame| {
561+ if !frame. code . is_allowed ( ) {
562+ CloseFrame {
568563 code : CloseCode :: Protocol ,
569564 reason : "Protocol violation" . into ( ) ,
570- } ) )
565+ }
566+ } else {
567+ frame
571568 }
572- } else {
573- Frame :: close ( None )
574- } ;
569+ } ) ;
570+
571+ let reply = Frame :: close ( close . clone ( ) ) ;
575572 debug ! ( "Replying to close with {:?}" , reply) ;
576573 self . send_queue . push_back ( reply) ;
577574
You can’t perform that action at this time.
0 commit comments