Echo the `CloseFrame` when close is initiated

pull/246/head
Daniel Abramov 3 years ago
parent 89697449ff
commit 5ad8cef6ff
  1. 23
      src/protocol/mod.rs

@ -555,23 +555,20 @@ impl WebSocketContext {
debug!("Received close frame: {:?}", close); debug!("Received close frame: {:?}", close);
match self.state { match self.state {
WebSocketState::Active => { WebSocketState::Active => {
let close_code = close.as_ref().map(|f| f.code);
self.state = WebSocketState::ClosedByPeer; self.state = WebSocketState::ClosedByPeer;
let reply = if let Some(code) = close_code {
if code.is_allowed() { let close = close.map(|frame| {
Frame::close(Some(CloseFrame { if !frame.code.is_allowed() {
code: CloseCode::Normal, CloseFrame {
reason: "".into(),
}))
} else {
Frame::close(Some(CloseFrame {
code: CloseCode::Protocol, code: CloseCode::Protocol,
reason: "Protocol violation".into(), reason: "Protocol violation".into(),
})) }
} else {
frame
} }
} else { });
Frame::close(None)
}; let reply = Frame::close(close.clone());
debug!("Replying to close with {:?}", reply); debug!("Replying to close with {:?}", reply);
self.send_queue.push_back(reply); self.send_queue.push_back(reply);

Loading…
Cancel
Save