Skip to content

Commit

Permalink
chore: naming alignemnt
Browse files Browse the repository at this point in the history
  • Loading branch information
SachaMorard committed Oct 18, 2024
1 parent 37a126b commit 79ff561
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
10 changes: 2 additions & 8 deletions src/proxy/compute/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,8 @@ pub async fn json_handler(
path: &PathAndQuery,
request_headers: &HeaderMap,
client_ip: &String,
) -> Result<String, &'static str> {
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<String> {
data_collection::process_from_json(body, cookie, path, request_headers, client_ip).await
}

/// Processes the payload of a request under certain conditions.
Expand Down
12 changes: 6 additions & 6 deletions src/proxy/compute/data_collection/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub async fn process_from_html(
request_headers: &HeaderMap,
client_ip: &String,
) -> Option<String> {
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/controller/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/proxy/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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#"<script id="__EDGEE_DATA_LAYER__" type="application/json">{}</script>"#;
Expand All @@ -270,7 +270,7 @@ pub async fn handle_request(
r#"{}{}<script{}{}>{}</script>"#,
debug_script,
empty_data_layer,
page_event_param,
client_side_param,
event_path_param,
document.inlined_sdk.as_str(),
);
Expand All @@ -281,7 +281,7 @@ pub async fn handle_request(
r#"{}{}<script{}{} async src="{}"></script>"#,
debug_script,
empty_data_layer,
page_event_param,
client_side_param,
event_path_param,
document.sdk_src.as_str()
);
Expand Down

0 comments on commit 79ff561

Please sign in to comment.