Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
#[serde(rename = "requestContext")]
pub request_context: RequestContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
#[serde(rename = "requestContext")]
pub request_context: RequestContext,
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
#[serde(rename = "requestContext")]
pub request_context: RequestContext,
Expand Down
23 changes: 10 additions & 13 deletions bottlecap/src/lifecycle/invocation/triggers/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,19 +68,16 @@ pub fn get_aws_partition_by_region(region: &str) -> String {

/// Serialize a `HashMap` with lowercase keys
///
pub fn lowercase_key<S, H>(
map: &HashMap<String, String, H>,
serializer: S,
) -> Result<S::Ok, S::Error>
pub fn lowercase_key<'de, D, V>(deserializer: D) -> Result<HashMap<String, V>, 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::<String, V>::deserialize(deserializer)?;
Ok(map
.into_iter()
.map(|(key, value)| (key.to_lowercase(), value))
.collect())
}

#[cfg(test)]
Expand Down
22 changes: 11 additions & 11 deletions bottlecap/tests/payloads/api_gateway_http_event.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading