connection: enforce that response to OPTIONS is SUPPORTED
The response to an OPTIONS message is always a SUPPORTED message. This
commit modifies the handshake logic so that it checks that it happens.
@@ -1180,8 +1180,15 @@ pub async fn open_named_connection(
false => "SCYLLA_SHARD_AWARE_PORT",
};
- let (shard_info, supported_compression, shard_aware_port) = match options_result {
- Response::Supported(mut supported) => {
+ let mut supported = match options_result {
+ Response::Supported(supported) => supported,
+ _ => {
+ return Err(QueryError::ProtocolError(
+ "Wrong response to OPTIONS message was received",
+ ));
+ }
+ };
+
let shard_info = ShardInfo::try_from(&supported.options).ok();
let supported_compression = supported.options.remove("COMPRESSION").unwrap_or_default();
let shard_aware_port = supported
@@ -1191,10 +1198,6 @@ pub async fn open_named_connection(
.into_iter()
.next()
.and_then(|p| p.parse::<u16>().ok());
- (shard_info, supported_compression, shard_aware_port)
- }
- _ => (None, Vec::new(), None),
- };
let features = ConnectionFeatures {
shard_info,
