Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup compression reject #990

Merged
merged 4 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions shotover-proxy/src/codec/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ impl Decoder for CassandraCodec {

let mut message = Message::from_bytes(bytes.freeze(), MessageType::Cassandra);

// if is startup message, reject compression because shotover does not support
if let Some(Frame::Cassandra(frame)) = message.frame() {
if let CassandraOperation::Startup(startup) = &mut frame.operation {
if let Some(compression) = startup.map.get("COMPRESSION") {
return Err(reject_compression(frame.stream_id, compression));
}
}
}

if let Ok(Metadata::Cassandra(CassandraMetadata {
opcode: Opcode::Query | Opcode::Batch,
..
Expand Down Expand Up @@ -196,6 +205,26 @@ fn reject_protocol_version(version: u8) -> CodecReadError {
))])
}

fn reject_compression(stream_id: i16, compression: &String) -> CodecReadError {
info!(
"Rejecting compression option {} (configure the client to use no compression)",
compression
);

CodecReadError::RespondAndThenCloseConnection(vec![Message::from_frame(Frame::Cassandra(
CassandraFrame {
version: Version::V4,
stream_id,
operation: CassandraOperation::Error(ErrorBody {
message: format!("Unsupported compression type {}", compression),
ty: ErrorType::Protocol,
}),
tracing: Tracing::Response(None),
warnings: vec![],
},
))])
}

impl Encoder<Messages> for CassandraCodec {
type Error = anyhow::Error;

Expand Down