mirror of https://github.com/fafhrd91/actix-web
Fix issues around initialization of fragmented payloads
This commit is contained in:
parent
4895fcb4c2
commit
93484512b8
|
@ -456,18 +456,18 @@ where
|
||||||
enum Collector {
|
enum Collector {
|
||||||
Text(BytesMut),
|
Text(BytesMut),
|
||||||
Binary(BytesMut),
|
Binary(BytesMut),
|
||||||
None
|
Uninitialized
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collector {
|
impl Collector {
|
||||||
fn take(&mut self) -> Collector {
|
fn take(&mut self) -> Collector {
|
||||||
std::mem::replace(self, Collector::None)
|
std::mem::replace(self, Collector::Uninitialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_none(&self) -> bool {
|
fn is_initialized(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Collector::None => true,
|
Collector::Text(_) | Collector::Binary(_) => true,
|
||||||
_ => false,
|
Collector::Uninitialized => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ where
|
||||||
stream,
|
stream,
|
||||||
decoder: codec,
|
decoder: codec,
|
||||||
buf: BytesMut::new(),
|
buf: BytesMut::new(),
|
||||||
collector: Collector::None,
|
collector: Collector::Uninitialized,
|
||||||
closed: false,
|
closed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -555,8 +555,8 @@ where
|
||||||
Frame::BeginText(data) => {
|
Frame::BeginText(data) => {
|
||||||
let data = data.unwrap_or_else(|| BytesMut::new());
|
let data = data.unwrap_or_else(|| BytesMut::new());
|
||||||
|
|
||||||
if self.collector.is_none() {
|
if self.collector.is_initialized() {
|
||||||
// Previous collection was not finalized
|
// Previous collection was already finalized
|
||||||
return Err(ProtocolError::NoContinuation);
|
return Err(ProtocolError::NoContinuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,8 +566,8 @@ where
|
||||||
Frame::BeginBinary(data) => {
|
Frame::BeginBinary(data) => {
|
||||||
let data = data.unwrap_or_else(|| BytesMut::new());
|
let data = data.unwrap_or_else(|| BytesMut::new());
|
||||||
|
|
||||||
if self.collector.is_none() {
|
if self.collector.is_initialized() {
|
||||||
// Previous collection was not finalized
|
// Previous collection was already finalized
|
||||||
return Err(ProtocolError::NoContinuation);
|
return Err(ProtocolError::NoContinuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,7 +602,7 @@ where
|
||||||
Some(Message::Binary(buf.freeze()))
|
Some(Message::Binary(buf.freeze()))
|
||||||
}
|
}
|
||||||
// Uninitialized continuation
|
// Uninitialized continuation
|
||||||
Collector::None => return Err(ProtocolError::NoContinuation),
|
Collector::Uninitialized => return Err(ProtocolError::NoContinuation),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue