1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-25 02:54:06 +00:00

Log errors

This commit is contained in:
Maciej Hirsz 2019-11-05 17:15:53 +01:00
parent 1be9ecf668
commit b5b91fce05
2 changed files with 16 additions and 2 deletions

View file

@ -104,13 +104,21 @@ impl Decoder for Codec {
Ok(Some((finished, opcode, payload))) => { Ok(Some((finished, opcode, payload))) => {
// continuation is not supported // continuation is not supported
if !finished { if !finished {
error!("No continuation 1");
return Err(ProtocolError::NoContinuation); return Err(ProtocolError::NoContinuation);
} }
match opcode { match opcode {
OpCode::Continue => Err(ProtocolError::NoContinuation), OpCode::Continue => {
OpCode::Bad => Err(ProtocolError::BadOpCode), error!("No continuation 2");
Err(ProtocolError::NoContinuation)
}
OpCode::Bad => {
error!("Bad opcode");
Err(ProtocolError::BadOpCode)
}
OpCode::Close => { OpCode::Close => {
warn!("Got a close frame!");
if let Some(ref pl) = payload { if let Some(ref pl) = payload {
let close_reason = Parser::parse_close_payload(pl); let close_reason = Parser::parse_close_payload(pl);
Ok(Some(Frame::Close(close_reason))) Ok(Some(Frame::Close(close_reason)))

View file

@ -32,8 +32,10 @@ impl Parser {
// check masking // check masking
let masked = second & 0x80 != 0; let masked = second & 0x80 != 0;
if !masked && server { if !masked && server {
error!("Protocol unmasked frame");
return Err(ProtocolError::UnmaskedFrame); return Err(ProtocolError::UnmaskedFrame);
} else if masked && !server { } else if masked && !server {
error!("Protocol masked frame");
return Err(ProtocolError::MaskedFrame); return Err(ProtocolError::MaskedFrame);
} }
@ -41,6 +43,7 @@ impl Parser {
let opcode = OpCode::from(first & 0x0F); let opcode = OpCode::from(first & 0x0F);
if let OpCode::Bad = opcode { if let OpCode::Bad = opcode {
error!("Protocol invalid opcode");
return Err(ProtocolError::InvalidOpcode(first & 0x0F)); return Err(ProtocolError::InvalidOpcode(first & 0x0F));
} }
@ -60,6 +63,7 @@ impl Parser {
} }
let len = u64::from_be_bytes(TryFrom::try_from(&src[idx..idx + 8]).unwrap()); let len = u64::from_be_bytes(TryFrom::try_from(&src[idx..idx + 8]).unwrap());
if len > max_size as u64 { if len > max_size as u64 {
error!("Protocol overflow 1");
return Err(ProtocolError::Overflow); return Err(ProtocolError::Overflow);
} }
idx += 8; idx += 8;
@ -70,6 +74,7 @@ impl Parser {
// check for max allowed size // check for max allowed size
if length > max_size { if length > max_size {
error!("Protocol overflow 2");
return Err(ProtocolError::Overflow); return Err(ProtocolError::Overflow);
} }
@ -120,6 +125,7 @@ impl Parser {
// control frames must have length <= 125 // control frames must have length <= 125
match opcode { match opcode {
OpCode::Ping | OpCode::Pong if length > 125 => { OpCode::Ping | OpCode::Pong if length > 125 => {
error!("Protocol invalid length");
return Err(ProtocolError::InvalidLength(length)); return Err(ProtocolError::InvalidLength(length));
} }
OpCode::Close if length > 125 => { OpCode::Close if length > 125 => {