use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageFrame {
pub id: String, pub timestamp: u64, pub target_id: Option<String>,
pub payload: MessagePayload,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MessagePayload {
Request(Request),
Response(Response),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Request {
pub sender_id: String, pub request_id: String,
pub service_id: String,
pub endpoint: Option<String>,
pub request_type: String, pub method: String, pub payload: String,
pub headers: HashMap<String, String>, pub payload_encrypted: bool,
pub signature: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Response {
pub request_id: String,
pub status_code: u16,
pub content_type: String,
pub payload: String,
pub headers: HashMap<String, String>, pub is_stream_chunk: bool,
pub stream_done: bool,
}
pub const ESSENTIAL_REQUEST_HEADERS: &[&str] = &[
"content-type",
"content-length",
"authorization",
"accept",
"accept-encoding",
"user-agent",
"x-forwarded-for",
"x-real-ip",
];
pub const ESSENTIAL_RESPONSE_HEADERS: &[&str] = &[
"content-type",
"content-length",
"content-encoding",
"cache-control",
"expires",
"last-modified",
"etag",
"access-control-allow-origin",
"access-control-allow-methods",
"access-control-allow-headers",
];
pub fn filter_essential_headers(
headers: &HashMap<String, String>,
essential: &[&str],
) -> HashMap<String, String> {
headers
.iter()
.filter(|(key, _)| {
let key_lower = key.to_lowercase();
essential
.iter()
.any(|&essential_key| key_lower == essential_key)
})
.map(|(k, v)| (k.clone(), v.clone()))
.collect()
}