(
&mut self,
envoy_filter: &mut ENF,
read_buffer_length: usize,
_end_stream: bool,
)
| 334 | } |
| 335 | |
| 336 | fn on_read( |
| 337 | &mut self, |
| 338 | envoy_filter: &mut ENF, |
| 339 | read_buffer_length: usize, |
| 340 | _end_stream: bool, |
| 341 | ) -> abi::envoy_dynamic_module_type_on_network_filter_data_status { |
| 342 | let _ = envoy_filter.increment_counter(self.bytes_received, read_buffer_length as u64); |
| 343 | |
| 344 | // Get data from read buffer. |
| 345 | let (chunks, _) = envoy_filter.get_read_buffer_chunks(); |
| 346 | |
| 347 | // Collect all bytes. |
| 348 | let mut data = Vec::new(); |
| 349 | for chunk in chunks { |
| 350 | data.extend_from_slice(chunk.as_slice()); |
| 351 | } |
| 352 | |
| 353 | // Check for command length limit. |
| 354 | if data.len() > self.max_command_length { |
| 355 | envoy_log_info!( |
| 356 | "Redis command exceeds max length: {} > {}", |
| 357 | data.len(), |
| 358 | self.max_command_length |
| 359 | ); |
| 360 | let _ = envoy_filter.increment_counter(self.parse_errors, 1); |
| 361 | envoy_filter.drain_read_buffer(read_buffer_length); |
| 362 | envoy_filter.write(&self.create_error_response("command too long"), false); |
| 363 | return abi::envoy_dynamic_module_type_on_network_filter_data_status::StopIteration; |
| 364 | } |
| 365 | |
| 366 | // Parse Redis commands. |
| 367 | match self.parse_commands(&data) { |
| 368 | Ok(commands) => { |
| 369 | for cmd in &commands { |
| 370 | let _ = envoy_filter.increment_counter(self.commands_total, 1); |
| 371 | |
| 372 | if self.log_commands { |
| 373 | let args_str: Vec<String> = cmd |
| 374 | .args |
| 375 | .iter() |
| 376 | .take(3) |
| 377 | .map(|a| String::from_utf8_lossy(a).to_string()) |
| 378 | .collect(); |
| 379 | envoy_log_debug!("Redis command: {} {:?}", cmd.name, args_str); |
| 380 | } |
| 381 | |
| 382 | // Check if command is blocked. |
| 383 | if self.blocked_commands.contains(&cmd.name) { |
| 384 | envoy_log_info!("Blocked Redis command: {}", cmd.name); |
| 385 | let _ = envoy_filter.increment_counter(self.commands_blocked, 1); |
| 386 | |
| 387 | // Drain the read buffer and send error response. |
| 388 | envoy_filter.drain_read_buffer(read_buffer_length); |
| 389 | let error_msg = format!("command '{}' is not allowed", cmd.name); |
| 390 | envoy_filter.write(&self.create_error_response(&error_msg), false); |
| 391 | return abi::envoy_dynamic_module_type_on_network_filter_data_status::StopIteration; |
| 392 | } |
| 393 | } |
nothing calls this directly
no test coverage detected