1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

use Optional with websocket close reason

This commit is contained in:
Nathan Fox
2018-04-21 16:50:27 -04:00
parent 2adf8a3a48
commit de8a09254d
6 changed files with 87 additions and 67 deletions

View File

@@ -66,8 +66,7 @@ mod proto;
pub use self::client::{Client, ClientError, ClientHandshake, ClientReader, ClientWriter};
pub use self::context::WebsocketContext;
pub use self::frame::Frame;
pub use self::proto::CloseCode;
pub use self::proto::OpCode;
pub use self::proto::{CloseCode, CloseReason, OpCode};
/// Websocket protocol errors
#[derive(Fail, Debug)]
@@ -164,7 +163,7 @@ pub enum Message {
Binary(Binary),
Ping(String),
Pong(String),
Close(CloseCode),
Close(Option<CloseReason>),
}
/// Do websocket handshake and start actor
@@ -310,15 +309,8 @@ where
}
OpCode::Close => {
self.closed = true;
let close_code = if payload.len() >= 2 {
let raw_code =
NetworkEndian::read_uint(payload.as_ref(), 2) as u16;
CloseCode::from(raw_code)
} else {
CloseCode::Status
};
Ok(Async::Ready(Some(Message::Close(close_code))))
let close_reason = Frame::parse_close_payload(&payload);
Ok(Async::Ready(Some(Message::Close(close_reason))))
}
OpCode::Ping => Ok(Async::Ready(Some(Message::Ping(
String::from_utf8_lossy(payload.as_ref()).into(),