From 79ff561ba2ad2050762be224d1f260ff0799cef6 Mon Sep 17 00:00:00 2001 From: Sacha Morard <2254275+SachaMorard@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:07:49 +0200 Subject: [PATCH] chore: naming alignemnt --- src/proxy/compute/compute.rs | 10 ++-------- src/proxy/compute/data_collection/data_collection.rs | 12 ++++++------ src/proxy/controller/controller.rs | 4 ++-- src/proxy/proxy.rs | 10 +++++----- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/proxy/compute/compute.rs b/src/proxy/compute/compute.rs index 3c0189e..2e26e40 100644 --- a/src/proxy/compute/compute.rs +++ b/src/proxy/compute/compute.rs @@ -90,14 +90,8 @@ pub async fn json_handler( path: &PathAndQuery, request_headers: &HeaderMap, client_ip: &String, -) -> Result { - let data_collection_events = - data_collection::process_from_json(body, cookie, path, request_headers, client_ip).await; - if data_collection_events.is_some() { - Ok(data_collection_events.unwrap()) - } else { - Err("compute-aborted(no-events)") - } +) -> Option { + data_collection::process_from_json(body, cookie, path, request_headers, client_ip).await } /// Processes the payload of a request under certain conditions. diff --git a/src/proxy/compute/data_collection/data_collection.rs b/src/proxy/compute/data_collection/data_collection.rs index b99216d..8d14a6c 100644 --- a/src/proxy/compute/data_collection/data_collection.rs +++ b/src/proxy/compute/data_collection/data_collection.rs @@ -30,13 +30,13 @@ pub async fn process_from_html( request_headers: &HeaderMap, client_ip: &String, ) -> Option { - let json_context = document.data_layer.clone(); + let json_data_layer = document.data_layer.clone(); let mut payload = Payload::default(); - if !json_context.is_empty() { - // Clean the json_context from comments and spaces - let stripped_context = StripComments::new(json_context.as_bytes()); - // populate the edgee payload from the json - let payload_result = parse_payload(stripped_context); + if !json_data_layer.is_empty() { + // Clean the json_data_layer from comments and spaces + let stripped_data_layer = StripComments::new(json_data_layer.as_bytes()); + // populate the edgee data_layer from the json + let payload_result = parse_payload(stripped_data_layer); if payload_result.is_err() { warn!("Error parsing json payload: {:?}", payload_result.err()); } else { diff --git a/src/proxy/controller/controller.rs b/src/proxy/controller/controller.rs index 955dcb0..1b9adf9 100644 --- a/src/proxy/controller/controller.rs +++ b/src/proxy/controller/controller.rs @@ -36,7 +36,7 @@ pub async fn edgee_client_event( if body.len() > 0 { let data_collection_events_res = compute::json_handler(&body, &cookie, path, request_headers, client_ip).await; - if data_collection_events_res.is_ok() { + if data_collection_events_res.is_some() { data_collection_events = data_collection_events_res.unwrap(); } } @@ -87,7 +87,7 @@ pub async fn edgee_client_event_from_third_party_sdk( if body.len() > 0 { let data_collection_events_res = compute::json_handler(&body, &cookie, path, request_headers, client_ip).await; - if data_collection_events_res.is_ok() { + if data_collection_events_res.is_some() { data_collection_events = data_collection_events_res.unwrap(); } } diff --git a/src/proxy/proxy.rs b/src/proxy/proxy.rs index 58ec3ac..ce3a27d 100644 --- a/src/proxy/proxy.rs +++ b/src/proxy/proxy.rs @@ -242,7 +242,7 @@ pub async fn handle_request( .await { Ok(document) => { - let mut page_event_param = r#" data-client-side="true""#; + let mut client_side_param = r#" data-client-side="true""#; let event_path_param = format!( r#" data-event-path="{}""#, path::generate(&incoming_host.as_str()) @@ -256,10 +256,10 @@ pub async fn handle_request( document.data_collection_events ); } - page_event_param = r#" data-client-side="false""#; + client_side_param = r#" data-client-side="false""#; } - // if the context is empty, we need to add an empty context script tag + // if the data_layer is empty, we need to add an empty data_layer script tag let mut empty_data_layer = ""; if document.data_layer.is_empty() { empty_data_layer = r#""#; @@ -270,7 +270,7 @@ pub async fn handle_request( r#"{}{}{}"#, debug_script, empty_data_layer, - page_event_param, + client_side_param, event_path_param, document.inlined_sdk.as_str(), ); @@ -281,7 +281,7 @@ pub async fn handle_request( r#"{}{}"#, debug_script, empty_data_layer, - page_event_param, + client_side_param, event_path_param, document.sdk_src.as_str() );