aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-07-24 01:47:39 +0200
committeracdenisSK <[email protected]>2017-07-24 01:51:36 +0200
commite72e25cf8b0160a3ec0de0be98dd8f1467d3b505 (patch)
tree0509c1cefea9f1fc95a8b50d3f0556becdb16603 /src/internal
parentAlso ignore data frame errors (diff)
downloadserenity-e72e25cf8b0160a3ec0de0be98dd8f1467d3b505.tar.xz
serenity-e72e25cf8b0160a3ec0de0be98dd8f1467d3b505.zip
Revert the ignoring of protocol and data frame errors, while actually handling ping pongs
When receiving pings, serenity MUST send the pong with the same data as the ping. Well, as said in the rfc for websockets anyway. Though, regarding the errors, i found out that serenity's gateway wouldn't work, but i do see that i'll have to file an issue to see if they know why are these happening at all
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/ws_impl.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/internal/ws_impl.rs b/src/internal/ws_impl.rs
index 0db40ee..8366a23 100644
--- a/src/internal/ws_impl.rs
+++ b/src/internal/ws_impl.rs
@@ -17,36 +17,40 @@ pub trait SenderExt {
impl ReceiverExt for WsClient<TlsStream<TcpStream>> {
fn recv_json<F, T>(&mut self, decode: F) -> Result<T> where F: FnOnce(Value) -> Result<T> {
- match self.recv_message()? {
+ let message = self.recv_message()?;
+
+ if let OwnedMessage::Ping(ref x) = message {
+ self.send_message(&OwnedMessage::Pong(x.clone())).map_err(Error::from)?;
+ }
+
+ let res = match message {
OwnedMessage::Binary(bytes) => {
let value = serde_json::from_reader(ZlibDecoder::new(&bytes[..]))?;
- decode(value).map_err(|why| {
+ Some(decode(value).map_err(|why| {
let s = String::from_utf8_lossy(&bytes);
warn!("(╯°□°)╯︵ ┻━┻ Error decoding: {}", s);
why
- })
+ }))
},
OwnedMessage::Close(data) => {
- Err(Error::Gateway(GatewayError::Closed(data)))
+ Some(Err(Error::Gateway(GatewayError::Closed(data))))
},
OwnedMessage::Text(payload) => {
let value = serde_json::from_str(&payload)?;
- decode(value).map_err(|why| {
+ Some(decode(value).map_err(|why| {
warn!("(╯°□°)╯︵ ┻━┻ Error decoding: {}", payload);
why
- })
+ }))
},
- OwnedMessage::Ping(x) | OwnedMessage::Pong(x) => {
- warn!("Unexpectly got ping/pong: {:?}", x);
-
- Err(Error::Gateway(GatewayError::Closed(None)))
- },
- }
+ OwnedMessage::Ping(..) | OwnedMessage::Pong(..) => None,
+ };
+
+ res.unwrap()
}
}