diff --git a/bottlecap/src/lifecycle/invocation/triggers/api_gateway_http_event.rs b/bottlecap/src/lifecycle/invocation/triggers/api_gateway_http_event.rs index cdf372001..69673cc2f 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/api_gateway_http_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/api_gateway_http_event.rs @@ -16,7 +16,7 @@ use crate::lifecycle::invocation::{ pub struct APIGatewayHttpEvent { #[serde(rename = "routeKey")] pub route_key: String, - #[serde(serialize_with = "lowercase_key")] + #[serde(deserialize_with = "lowercase_key")] pub headers: HashMap, #[serde(rename = "requestContext")] pub request_context: RequestContext, diff --git a/bottlecap/src/lifecycle/invocation/triggers/api_gateway_rest_event.rs b/bottlecap/src/lifecycle/invocation/triggers/api_gateway_rest_event.rs index 67a1180be..5e725163d 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/api_gateway_rest_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/api_gateway_rest_event.rs @@ -14,7 +14,7 @@ use crate::lifecycle::invocation::{ #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct APIGatewayRestEvent { - #[serde(serialize_with = "lowercase_key")] + #[serde(deserialize_with = "lowercase_key")] pub headers: HashMap, #[serde(rename = "requestContext")] pub request_context: RequestContext, @@ -205,8 +205,8 @@ mod tests { let expected = APIGatewayRestEvent { headers: HashMap::from([ - ("Header1".to_string(), "value1".to_string()), - ("Header2".to_string(), "value2".to_string()), + ("header1".to_string(), "value1".to_string()), + ("header2".to_string(), "value2".to_string()), ]), request_context: RequestContext { stage: "$default".to_string(), diff --git a/bottlecap/src/lifecycle/invocation/triggers/lambda_function_url_event.rs b/bottlecap/src/lifecycle/invocation/triggers/lambda_function_url_event.rs index 18bdc734d..1b4262230 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/lambda_function_url_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/lambda_function_url_event.rs @@ -11,7 +11,7 @@ use crate::lifecycle::invocation::{ #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct LambdaFunctionUrlEvent { - #[serde(serialize_with = "lowercase_key")] + #[serde(deserialize_with = "lowercase_key")] pub headers: HashMap, #[serde(rename = "requestContext")] pub request_context: RequestContext, diff --git a/bottlecap/src/lifecycle/invocation/triggers/mod.rs b/bottlecap/src/lifecycle/invocation/triggers/mod.rs index 2f9a0100a..c089aff75 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/mod.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/mod.rs @@ -1,7 +1,7 @@ -use std::{collections::HashMap, hash::BuildHasher}; +use std::collections::HashMap; use datadog_trace_protobuf::pb::Span; -use serde::{ser::SerializeMap, Serializer}; +use serde::{Deserialize, Deserializer}; use serde_json::Value; pub mod api_gateway_http_event; @@ -68,19 +68,16 @@ pub fn get_aws_partition_by_region(region: &str) -> String { /// Serialize a `HashMap` with lowercase keys /// -pub fn lowercase_key( - map: &HashMap, - serializer: S, -) -> Result +pub fn lowercase_key<'de, D, V>(deserializer: D) -> Result, D::Error> where - S: Serializer, - H: BuildHasher, + D: Deserializer<'de>, + V: Deserialize<'de>, { - let mut map_serializer = serializer.serialize_map(Some(map.len()))?; - for (key, value) in map { - map_serializer.serialize_entry(&key.to_lowercase(), value)?; - } - map_serializer.end() + let map = HashMap::::deserialize(deserializer)?; + Ok(map + .into_iter() + .map(|(key, value)| (key.to_lowercase(), value)) + .collect()) } #[cfg(test)] diff --git a/bottlecap/tests/payloads/api_gateway_http_event.json b/bottlecap/tests/payloads/api_gateway_http_event.json index 061a02522..fce343a27 100644 --- a/bottlecap/tests/payloads/api_gateway_http_event.json +++ b/bottlecap/tests/payloads/api_gateway_http_event.json @@ -4,17 +4,17 @@ "rawPath": "/httpapi/get", "rawQueryString": "", "headers": { - "accept": "*/*", - "content-length": "0", - "host": "x02yirxc7a.execute-api.sa-east-1.amazonaws.com", - "user-agent": "curl/7.64.1", - "x-amzn-trace-id": "Root=1-613a52fb-4c43cfc95e0241c1471bfa05", - "x-forwarded-for": "38.122.226.210", - "x-forwarded-port": "443", - "x-forwarded-proto": "https", - "x-datadog-trace-id": "12345", - "x-datadog-parent-id": "67890", - "x-datadog-sampling-priority": "2" + "Accept": "*/*", + "Content-Length": "0", + "Host": "x02yirxc7a.execute-api.sa-east-1.amazonaws.com", + "User-Agent": "curl/7.64.1", + "X-amzn-trace-id": "Root=1-613a52fb-4c43cfc95e0241c1471bfa05", + "X-forwarded-for": "38.122.226.210", + "X-forwarded-port": "443", + "X-forwarded-proto": "https", + "X-datadog-trace-id": "12345", + "X-datadog-parent-id": "67890", + "X-datadog-sampling-priority": "2" }, "requestContext": { "accountId": "425362996713",