mirror of https://github.com/fafhrd91/actix-web
Return Async::NotReady while concating fragments
This commit is contained in:
parent
6052452094
commit
21b6ba7216
|
@ -542,24 +542,18 @@ where
|
||||||
Some(frm) => {
|
Some(frm) => {
|
||||||
let msg = match frm {
|
let msg = match frm {
|
||||||
Frame::Text(data) => {
|
Frame::Text(data) => {
|
||||||
Some(if let Some(data) = data {
|
if let Some(data) = data {
|
||||||
let text = std::str::from_utf8(&data);
|
Message::Text(std::str::from_utf8(&data)?.to_string())
|
||||||
|
|
||||||
if text.is_err() {
|
|
||||||
error!("Invalid UTF-8 encoding");
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::Text(text?.to_string())
|
|
||||||
} else {
|
} else {
|
||||||
Message::Text(String::new())
|
Message::Text(String::new())
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
Frame::Binary(data) => Some(Message::Binary(
|
Frame::Binary(data) => Message::Binary(
|
||||||
data.map(|b| b.freeze()).unwrap_or_else(Bytes::new),
|
data.map(|b| b.freeze()).unwrap_or_else(Bytes::new),
|
||||||
)),
|
),
|
||||||
Frame::Ping(s) => Some(Message::Ping(s)),
|
Frame::Ping(s) => Message::Ping(s),
|
||||||
Frame::Pong(s) => Some(Message::Pong(s)),
|
Frame::Pong(s) => Message::Pong(s),
|
||||||
Frame::Close(reason) => Some(Message::Close(reason)),
|
Frame::Close(reason) => Message::Close(reason),
|
||||||
Frame::BeginText(data) => {
|
Frame::BeginText(data) => {
|
||||||
let data = data.unwrap_or_else(|| BytesMut::new());
|
let data = data.unwrap_or_else(|| BytesMut::new());
|
||||||
|
|
||||||
|
@ -569,7 +563,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
self.collector = Collector::Text(data);
|
self.collector = Collector::Text(data);
|
||||||
None
|
|
||||||
|
return Ok(Async::NotReady);
|
||||||
}
|
}
|
||||||
Frame::BeginBinary(data) => {
|
Frame::BeginBinary(data) => {
|
||||||
let data = data.unwrap_or_else(|| BytesMut::new());
|
let data = data.unwrap_or_else(|| BytesMut::new());
|
||||||
|
@ -580,7 +575,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
self.collector = Collector::Binary(data);
|
self.collector = Collector::Binary(data);
|
||||||
None
|
|
||||||
|
return Ok(Async::NotReady);
|
||||||
}
|
}
|
||||||
Frame::Continue(data) => {
|
Frame::Continue(data) => {
|
||||||
let data = data.as_ref().map(|d| &**d).unwrap_or_else(|| &[]);
|
let data = data.as_ref().map(|d| &**d).unwrap_or_else(|| &[]);
|
||||||
|
@ -596,7 +592,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
return Ok(Async::NotReady);
|
||||||
}
|
}
|
||||||
Frame::End(data) => {
|
Frame::End(data) => {
|
||||||
let data = data.as_ref().map(|d| &**d).unwrap_or_else(|| &[]);
|
let data = data.as_ref().map(|d| &**d).unwrap_or_else(|| &[]);
|
||||||
|
@ -604,20 +600,11 @@ where
|
||||||
match self.collector.take() {
|
match self.collector.take() {
|
||||||
Collector::Text(mut buf) => {
|
Collector::Text(mut buf) => {
|
||||||
buf.extend_from_slice(data);
|
buf.extend_from_slice(data);
|
||||||
|
Message::Text(std::str::from_utf8(&buf)?.to_string())
|
||||||
let text = std::str::from_utf8(&buf);
|
|
||||||
|
|
||||||
if text.is_err() {
|
|
||||||
error!("Invalid UTF-8 encoding");
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(Message::Text(
|
|
||||||
text?.to_string()
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
Collector::Binary(mut buf) => {
|
Collector::Binary(mut buf) => {
|
||||||
buf.extend_from_slice(data);
|
buf.extend_from_slice(data);
|
||||||
Some(Message::Binary(buf.freeze()))
|
Message::Binary(buf.freeze())
|
||||||
}
|
}
|
||||||
// Uninitialized continuation
|
// Uninitialized continuation
|
||||||
Collector::Uninitialized => {
|
Collector::Uninitialized => {
|
||||||
|
@ -627,7 +614,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Async::Ready(msg))
|
Ok(Async::Ready(Some(msg)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue