Skip to content

Commit 949ed09

Browse files
committed
Fixed warnings
1 parent 9140024 commit 949ed09

File tree

4 files changed

+101
-56
lines changed

4 files changed

+101
-56
lines changed

src/gdpr.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use serde::{Deserialize, Serialize};
2-
use std::collections::HashMap;
3-
use fastly::{Error, Request, Response};
4-
use fastly::http::{header, Method, StatusCode};
51
use crate::cookies;
62
use crate::settings::Settings;
3+
use fastly::http::{header, Method, StatusCode};
4+
use fastly::{Error, Request, Response};
5+
use serde::{Deserialize, Serialize};
6+
use std::collections::HashMap;
77

88
#[derive(Debug, Serialize, Deserialize, Clone)]
99
pub struct GdprConsent {
@@ -63,7 +63,7 @@ pub fn create_consent_cookie(consent: &GdprConsent) -> String {
6363
)
6464
}
6565

66-
pub fn handle_consent_request(settings: &Settings, mut req: Request) -> Result<Response, Error> {
66+
pub fn handle_consent_request(_settings: &Settings, req: Request) -> Result<Response, Error> {
6767
match req.get_method() {
6868
&Method::GET => {
6969
// Return current consent status
@@ -78,47 +78,49 @@ pub fn handle_consent_request(settings: &Settings, mut req: Request) -> Result<R
7878
let mut response = Response::from_status(StatusCode::OK)
7979
.with_header(header::CONTENT_TYPE, "application/json")
8080
.with_body(serde_json::to_string(&consent)?);
81-
81+
8282
response.set_header(header::SET_COOKIE, create_consent_cookie(&consent));
8383
Ok(response)
8484
}
85-
_ => Ok(Response::from_status(StatusCode::METHOD_NOT_ALLOWED)
86-
.with_body("Method not allowed"))
85+
_ => {
86+
Ok(Response::from_status(StatusCode::METHOD_NOT_ALLOWED)
87+
.with_body("Method not allowed"))
88+
}
8789
}
8890
}
8991

90-
pub fn handle_data_subject_request(settings: &Settings, req: Request) -> Result<Response, Error> {
92+
pub fn handle_data_subject_request(_settings: &Settings, req: Request) -> Result<Response, Error> {
9193
match req.get_method() {
9294
&Method::GET => {
9395
// Handle data access request
9496
if let Some(synthetic_id) = req.get_header("X-Subject-ID") {
9597
// Create a HashMap to store all user-related data
9698
let mut data: HashMap<String, UserData> = HashMap::new();
97-
99+
98100
// TODO: Implement actual data retrieval from KV store
99101
// For now, return empty user data
100102
data.insert(synthetic_id.to_str()?.to_string(), UserData::default());
101-
103+
102104
Ok(Response::from_status(StatusCode::OK)
103105
.with_header(header::CONTENT_TYPE, "application/json")
104106
.with_body(serde_json::to_string(&data)?))
105107
} else {
106-
Ok(Response::from_status(StatusCode::BAD_REQUEST)
107-
.with_body("Missing subject ID"))
108+
Ok(Response::from_status(StatusCode::BAD_REQUEST).with_body("Missing subject ID"))
108109
}
109110
}
110111
&Method::DELETE => {
111112
// Handle right to erasure (right to be forgotten)
112-
if let Some(synthetic_id) = req.get_header("X-Subject-ID") {
113+
if let Some(_synthetic_id) = req.get_header("X-Subject-ID") {
113114
// TODO: Implement data deletion from KV store
114115
Ok(Response::from_status(StatusCode::OK)
115116
.with_body("Data deletion request processed"))
116117
} else {
117-
Ok(Response::from_status(StatusCode::BAD_REQUEST)
118-
.with_body("Missing subject ID"))
118+
Ok(Response::from_status(StatusCode::BAD_REQUEST).with_body("Missing subject ID"))
119119
}
120120
}
121-
_ => Ok(Response::from_status(StatusCode::METHOD_NOT_ALLOWED)
122-
.with_body("Method not allowed"))
121+
_ => {
122+
Ok(Response::from_status(StatusCode::METHOD_NOT_ALLOWED)
123+
.with_body("Method not allowed"))
124+
}
123125
}
124-
}
126+
}

src/main.rs

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use fastly::geo::geo_lookup;
12
use fastly::http::{header, Method, StatusCode};
23
use fastly::KVStore;
34
use fastly::{Error, Request, Response};
4-
use fastly::geo::geo_lookup;
55
use log::LevelFilter::Info;
66
use serde_json::json;
77
use std::env;
@@ -64,28 +64,37 @@ fn main(req: Request) -> Result<Response, Error> {
6464
fn get_dma_code(req: &mut Request) -> Option<String> {
6565
// Debug: Check if we're running in Fastly environment
6666
println!("Fastly Environment Check:");
67-
println!(" FASTLY_POP: {}", std::env::var("FASTLY_POP").unwrap_or_else(|_| "not in Fastly".to_string()));
68-
println!(" FASTLY_REGION: {}", std::env::var("FASTLY_REGION").unwrap_or_else(|_| "not in Fastly".to_string()));
69-
67+
println!(
68+
" FASTLY_POP: {}",
69+
std::env::var("FASTLY_POP").unwrap_or_else(|_| "not in Fastly".to_string())
70+
);
71+
println!(
72+
" FASTLY_REGION: {}",
73+
std::env::var("FASTLY_REGION").unwrap_or_else(|_| "not in Fastly".to_string())
74+
);
75+
7076
// Get detailed geo information using geo_lookup
7177
if let Some(geo) = req.get_client_ip_addr().and_then(geo_lookup) {
7278
println!("Geo Information Found:");
73-
79+
7480
// Set all available geo information in headers
7581
let city = geo.city();
7682
req.set_header("X-Geo-City", city);
7783
println!(" City: {}", city);
78-
84+
7985
let country = geo.country_code();
8086
req.set_header("X-Geo-Country", country);
8187
println!(" Country: {}", country);
82-
88+
8389
req.set_header("X-Geo-Continent", format!("{:?}", geo.continent()));
8490
println!(" Continent: {:?}", geo.continent());
85-
86-
req.set_header("X-Geo-Coordinates", format!("{},{}", geo.latitude(), geo.longitude()));
91+
92+
req.set_header(
93+
"X-Geo-Coordinates",
94+
format!("{},{}", geo.latitude(), geo.longitude()),
95+
);
8796
println!(" Location: ({}, {})", geo.latitude(), geo.longitude());
88-
97+
8998
// Get and set the metro code (DMA)
9099
let metro_code = geo.metro_code();
91100
req.set_header("X-Geo-Metro-Code", metro_code.to_string());
@@ -122,7 +131,9 @@ fn handle_main_page(settings: &Settings, mut req: Request) -> Result<Response, E
122131
if !consent.functional {
123132
// Return a version of the page without tracking
124133
return Ok(Response::from_status(StatusCode::OK)
125-
.with_body(HTML_TEMPLATE.replace("fetch('/prebid-test')", "console.log('Tracking disabled')"))
134+
.with_body(
135+
HTML_TEMPLATE.replace("fetch('/prebid-test')", "console.log('Tracking disabled')"),
136+
)
126137
.with_header(header::CONTENT_TYPE, "text/html")
127138
.with_header(header::CACHE_CONTROL, "no-store, private"));
128139
}
@@ -157,7 +168,14 @@ fn handle_main_page(settings: &Settings, mut req: Request) -> Result<Response, E
157168
.with_header("x-compress-hint", "on");
158169

159170
// Copy geo headers from request to response
160-
for header_name in &["X-Geo-City", "X-Geo-Country", "X-Geo-Continent", "X-Geo-Coordinates", "X-Geo-Metro-Code", "X-Geo-Info-Available"] {
171+
for header_name in &[
172+
"X-Geo-City",
173+
"X-Geo-Country",
174+
"X-Geo-Continent",
175+
"X-Geo-Coordinates",
176+
"X-Geo-Metro-Code",
177+
"X-Geo-Info-Available",
178+
] {
161179
if let Some(value) = req.get_header(*header_name) {
162180
response.set_header(*header_name, value);
163181
}
@@ -191,15 +209,16 @@ fn handle_main_page(settings: &Settings, mut req: Request) -> Result<Response, E
191209

192210
fn handle_ad_request(settings: &Settings, mut req: Request) -> Result<Response, Error> {
193211
// Check GDPR consent to determine if we should serve personalized or non-personalized ads
194-
let consent = get_consent_from_request(&req).unwrap_or_default();
195-
let advertising_consent = req.get_header("X-Consent-Advertising")
212+
let _consent = get_consent_from_request(&req).unwrap_or_default();
213+
let advertising_consent = req
214+
.get_header("X-Consent-Advertising")
196215
.and_then(|h| h.to_str().ok())
197216
.map(|v| v == "true")
198217
.unwrap_or(false);
199218

200219
// Add DMA code extraction
201220
let dma_code = get_dma_code(&mut req);
202-
221+
203222
println!("Client location - DMA Code: {:?}", dma_code);
204223

205224
// Log headers for debugging
@@ -231,16 +250,14 @@ fn handle_ad_request(settings: &Settings, mut req: Request) -> Result<Response,
231250
println!("Fetching current count for synthetic ID: {}", synthetic_id);
232251
let current_count: i32 = store
233252
.lookup(&synthetic_id)
234-
.and_then(|mut val| {
235-
match String::from_utf8(val.take_body_bytes()) {
236-
Ok(s) => {
237-
println!("Value from KV store: {}", s);
238-
Ok(Some(s))
239-
}
240-
Err(e) => {
241-
println!("Error converting bytes to string: {}", e);
242-
Ok(None)
243-
}
253+
.and_then(|mut val| match String::from_utf8(val.take_body_bytes()) {
254+
Ok(s) => {
255+
println!("Value from KV store: {}", s);
256+
Ok(Some(s))
257+
}
258+
Err(e) => {
259+
println!("Error converting bytes to string: {}", e);
260+
Ok(None)
244261
}
245262
})
246263
.and_then(|opt_s| {
@@ -264,24 +281,33 @@ fn handle_ad_request(settings: &Settings, mut req: Request) -> Result<Response,
264281

265282
// Modify the ad server URL construction to include DMA code if available
266283
let ad_server_url = if advertising_consent {
267-
let mut url = settings.ad_server.sync_url.replace("{{synthetic_id}}", &synthetic_id);
284+
let mut url = settings
285+
.ad_server
286+
.sync_url
287+
.replace("{{synthetic_id}}", &synthetic_id);
268288
if let Some(dma) = dma_code {
269289
url = format!("{}&dma={}", url, dma);
270290
}
271291
url
272292
} else {
273293
// Use a different URL or parameter for non-personalized ads
274-
settings.ad_server.sync_url.replace("{{synthetic_id}}", "non-personalized")
294+
settings
295+
.ad_server
296+
.sync_url
297+
.replace("{{synthetic_id}}", "non-personalized")
275298
};
276299

277300
println!("Sending request to backend: {}", ad_server_url);
278301

279302
// Add header logging here
280303
let mut ad_req = Request::get(ad_server_url);
281-
304+
282305
// Add consent information to the ad request
283-
ad_req.set_header("X-Consent-Advertising", if advertising_consent { "true" } else { "false" });
284-
306+
ad_req.set_header(
307+
"X-Consent-Advertising",
308+
if advertising_consent { "true" } else { "false" },
309+
);
310+
285311
println!("Request headers to Equativ:");
286312
for (name, value) in ad_req.get_headers() {
287313
println!(" {}: {:?}", name, value);
@@ -395,7 +421,14 @@ fn handle_ad_request(settings: &Settings, mut req: Request) -> Result<Response,
395421
.with_body(body);
396422

397423
// Copy geo headers from request to response
398-
for header_name in &["X-Geo-City", "X-Geo-Country", "X-Geo-Continent", "X-Geo-Coordinates", "X-Geo-Metro-Code", "X-Geo-Info-Available"] {
424+
for header_name in &[
425+
"X-Geo-City",
426+
"X-Geo-Country",
427+
"X-Geo-Continent",
428+
"X-Geo-Coordinates",
429+
"X-Geo-Metro-Code",
430+
"X-Geo-Info-Available",
431+
] {
399432
if let Some(value) = req.get_header(*header_name) {
400433
response.set_header(*header_name, value);
401434
}
@@ -429,7 +462,8 @@ async fn handle_prebid_test(settings: &Settings, mut req: Request) -> Result<Res
429462
println!("Starting prebid test request handling");
430463

431464
// Check consent status from headers
432-
let advertising_consent = req.get_header("X-Consent-Advertising")
465+
let advertising_consent = req
466+
.get_header("X-Consent-Advertising")
433467
.and_then(|h| h.to_str().ok())
434468
.map(|v| v == "true")
435469
.unwrap_or(false);
@@ -441,7 +475,10 @@ async fn handle_prebid_test(settings: &Settings, mut req: Request) -> Result<Res
441475
(fresh, synth)
442476
} else {
443477
// Use non-personalized IDs when no consent
444-
("non-personalized".to_string(), "non-personalized".to_string())
478+
(
479+
"non-personalized".to_string(),
480+
"non-personalized".to_string(),
481+
)
445482
};
446483

447484
println!(
@@ -455,7 +492,10 @@ async fn handle_prebid_test(settings: &Settings, mut req: Request) -> Result<Res
455492
// Set both IDs as headers
456493
req.set_header(SYNTHETIC_HEADER_FRESH, &fresh_id);
457494
req.set_header(SYNTHETIC_HEADER_POTSI, &synthetic_id);
458-
req.set_header("X-Consent-Advertising", if advertising_consent { "true" } else { "false" });
495+
req.set_header(
496+
"X-Consent-Advertising",
497+
if advertising_consent { "true" } else { "false" },
498+
);
459499

460500
println!("Using POTSI ID: {}, Fresh ID: {}", synthetic_id, fresh_id);
461501

@@ -497,7 +537,10 @@ async fn handle_prebid_test(settings: &Settings, mut req: Request) -> Result<Res
497537
.with_header(header::CONTENT_TYPE, "application/json")
498538
.with_header("X-Prebid-Test", "true")
499539
.with_header("X-Synthetic-ID", &prebid_req.synthetic_id)
500-
.with_header("X-Consent-Advertising", if advertising_consent { "true" } else { "false" })
540+
.with_header(
541+
"X-Consent-Advertising",
542+
if advertising_consent { "true" } else { "false" },
543+
)
501544
.with_header("x-compress-hint", "on")
502545
.with_body(body))
503546
}

src/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ pub const PRIVACY_TEMPLATE: &str = r#"<!DOCTYPE html>
138138
<p class="last-updated">Last Updated: March 24, 2024</p>
139139
</div>
140140
</body>
141-
</html>"#;
141+
</html>"#;

src/why.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ pub const WHY_TEMPLATE: &str = r#"<!DOCTYPE html>
218218
</div>
219219
</div>
220220
</body>
221-
</html>"#;
221+
</html>"#;

0 commit comments

Comments
 (0)