Skip to content

Commit

Permalink
Allow new Message type Close to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ authored and seanmonstar committed Jan 16, 2020
1 parent db94f94 commit fef945c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/filters/ws.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Websockets Filters
use std::borrow::Cow;
use std::fmt;
use std::future::Future;
use std::io::{self, Read, Write};
Expand Down Expand Up @@ -411,6 +412,23 @@ impl Message {
}
}

/// Construct the default Close `Message`.
pub fn close() -> Message {
Message {
inner: protocol::Message::Close(None),
}
}

/// Construct a Close `Message` with a code and reason.
pub fn close_with(code: impl Into<u16>, reason: impl Into<Cow<'static, str>>) -> Message {
Message {
inner: protocol::Message::Close(Some(protocol::frame::CloseFrame {
code: protocol::frame::coding::CloseCode::from(code.into()),
reason: reason.into(),
})),
}
}

/// Returns true if this message is a Text message.
pub fn is_text(&self) -> bool {
self.inner.is_text()
Expand Down

0 comments on commit fef945c

Please sign in to comment.