Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo the CloseFrame when close is initiated #246

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,23 +555,20 @@ impl WebSocketContext {
debug!("Received close frame: {:?}", close);
match self.state {
WebSocketState::Active => {
let close_code = close.as_ref().map(|f| f.code);
self.state = WebSocketState::ClosedByPeer;
let reply = if let Some(code) = close_code {
if code.is_allowed() {
Frame::close(Some(CloseFrame {
code: CloseCode::Normal,
reason: "".into(),
}))
} else {
Frame::close(Some(CloseFrame {

let close = close.map(|frame| {
if !frame.code.is_allowed() {
CloseFrame {
code: CloseCode::Protocol,
reason: "Protocol violation".into(),
}))
}
} else {
frame
}
} else {
Frame::close(None)
};
});

let reply = Frame::close(close.clone());
debug!("Replying to close with {:?}", reply);
self.send_queue.push_back(reply);

Expand Down