Skip to content

Commit 48bd83a

Browse files
committed
Added synthetic trusted server ID header and cookies to publisher proxy responses.
1 parent d7ac23c commit 48bd83a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

crates/common/src/publisher.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,24 @@ pub fn handle_publisher_request(
347347

348348
log::info!("Request host: {}, scheme: {}", request_host, request_scheme);
349349

350+
// Generate synthetic identifiers before the request body is consumed.
351+
let synthetic_id = get_or_generate_synthetic_id(settings, &req)?;
352+
let has_synthetic_cookie = req
353+
.get_header(header::COOKIE)
354+
.and_then(|h| h.to_str().ok())
355+
.map(|cookies| {
356+
cookies
357+
.split(';')
358+
.any(|cookie| cookie.trim_start().starts_with("synthetic_id="))
359+
})
360+
.unwrap_or(false);
361+
362+
log::info!(
363+
"Proxy synthetic IDs - trusted: {}, has_cookie: {}",
364+
synthetic_id,
365+
has_synthetic_cookie
366+
);
367+
350368
// Extract host from the origin_url using the Publisher's origin_host method
351369
let origin_host = settings.publisher.origin_host();
352370

@@ -434,6 +452,14 @@ pub fn handle_publisher_request(
434452
);
435453
}
436454

455+
response.set_header(HEADER_SYNTHETIC_TRUSTED_SERVER, synthetic_id.as_str());
456+
if !has_synthetic_cookie {
457+
response.set_header(
458+
header::SET_COOKIE,
459+
create_synthetic_cookie(settings, synthetic_id.as_str()),
460+
);
461+
}
462+
437463
Ok(response)
438464
}
439465

0 commit comments

Comments
 (0)