From 0bf233c123818eb62cb25a5bcb4c9eed5f04fcf8 Mon Sep 17 00:00:00 2001 From: Javier Blazquez Date: Fri, 1 Nov 2024 20:24:05 -0700 Subject: [PATCH] http_server: Correct description of header injection behavior with conflicting fields --- src/sources/http_server.rs | 13 ++++++++++--- src/sources/opentelemetry/mod.rs | 2 +- .../cue/reference/components/sources/base/http.cue | 2 +- .../components/sources/base/http_server.cue | 2 +- .../components/sources/base/opentelemetry.cue | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/sources/http_server.rs b/src/sources/http_server.rs index 9777e0b9e1243..83d8550efd45a 100644 --- a/src/sources/http_server.rs +++ b/src/sources/http_server.rs @@ -91,7 +91,7 @@ pub struct SimpleHttpConfig { /// /// Specifying "*" results in all headers included in the log event. /// - /// These override any values included in the JSON payload with conflicting names. + /// These headers are not included in the JSON payload if a field with a conflicting name exists. #[serde(default)] #[configurable(metadata(docs::examples = "User-Agent"))] #[configurable(metadata(docs::examples = "X-My-Custom-Header"))] @@ -1084,6 +1084,8 @@ mod tests { let mut headers = HeaderMap::new(); headers.insert("User-Agent", "test_client".parse().unwrap()); headers.insert("X-Case-Sensitive-Value", "CaseSensitive".parse().unwrap()); + // Header that conflicts with an existing field. + headers.insert("key1", "value_from_header".parse().unwrap()); let (rx, addr) = source( vec!["*".to_string()], @@ -1183,7 +1185,11 @@ mod tests { .await; spawn_ok_collect_n( - send_with_query(addr, "{\"key1\":\"value1\"}", "source=staging®ion=gb"), + send_with_query( + addr, + "{\"key1\":\"value1\",\"key2\":\"value2\"}", + "source=staging®ion=gb&key1=value_from_query", + ), rx, 1, ) @@ -1194,7 +1200,8 @@ mod tests { { let event = events.remove(0); let log = event.as_log(); - assert_eq!(log["key1"], "value1".into()); + assert_eq!(log["key1"], "value_from_query".into()); + assert_eq!(log["key2"], "value2".into()); assert_eq!(log["source"], "staging".into()); assert_eq!(log["region"], "gb".into()); assert_event_metadata(log).await; diff --git a/src/sources/opentelemetry/mod.rs b/src/sources/opentelemetry/mod.rs index b73a8c7439d15..1b6764103594c 100644 --- a/src/sources/opentelemetry/mod.rs +++ b/src/sources/opentelemetry/mod.rs @@ -122,7 +122,7 @@ struct HttpConfig { /// /// Specifying "*" results in all headers included in the log event. /// - /// These override any values included in the JSON payload with conflicting names. + /// These headers are not included in the JSON payload if a field with a conflicting name exists. #[serde(default)] #[configurable(metadata(docs::examples = "User-Agent"))] #[configurable(metadata(docs::examples = "X-My-Custom-Header"))] diff --git a/website/cue/reference/components/sources/base/http.cue b/website/cue/reference/components/sources/base/http.cue index 380be1998be98..ab012e5a7c329 100644 --- a/website/cue/reference/components/sources/base/http.cue +++ b/website/cue/reference/components/sources/base/http.cue @@ -421,7 +421,7 @@ base: components: sources: http: configuration: { Specifying "*" results in all headers included in the log event. - These override any values included in the JSON payload with conflicting names. + These headers are not included in the JSON payload if a field with a conflicting name exists. """ required: false type: array: { diff --git a/website/cue/reference/components/sources/base/http_server.cue b/website/cue/reference/components/sources/base/http_server.cue index 1db251b62a950..f131c52747c34 100644 --- a/website/cue/reference/components/sources/base/http_server.cue +++ b/website/cue/reference/components/sources/base/http_server.cue @@ -421,7 +421,7 @@ base: components: sources: http_server: configuration: { Specifying "*" results in all headers included in the log event. - These override any values included in the JSON payload with conflicting names. + These headers are not included in the JSON payload if a field with a conflicting name exists. """ required: false type: array: { diff --git a/website/cue/reference/components/sources/base/opentelemetry.cue b/website/cue/reference/components/sources/base/opentelemetry.cue index 447b4c29c5887..5c2004cbe6999 100644 --- a/website/cue/reference/components/sources/base/opentelemetry.cue +++ b/website/cue/reference/components/sources/base/opentelemetry.cue @@ -176,7 +176,7 @@ base: components: sources: opentelemetry: configuration: { Specifying "*" results in all headers included in the log event. - These headers are not included in the JSON payload if field with conflicting names exists. + These headers are not included in the JSON payload if a field with a conflicting name exists. """ required: false type: array: {