Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Additional behavior:

Helpers:

- `rewrite_creative_html(markup, settings) -> String` — rewrite an HTML fragment
- `rewrite_css_body(css, settings) -> String` — rewrite a CSS body (`url(...)` entries)
- `rewrite_srcset(srcset, settings) -> String` — proxy absolute candidates; preserve descriptors (`1x`, `1.5x`, `100w`)
- `rewrite_creative_html(settings, markup) -> String` — rewrite an HTML fragment
- `rewrite_css_body(settings, css) -> String` — rewrite a CSS body (`url(...)` entries)
- `rewrite_srcset(settings, srcset) -> String` — proxy absolute candidates; preserve descriptors (`1x`, `1.5x`, `100w`)
- `split_srcset_candidates(srcset) -> Vec<&str>` — robust splitting for commas with/without spaces; avoids splitting the first `data:` mediatype comma

Static bundles (served by publisher module):
Expand Down
146 changes: 73 additions & 73 deletions crates/common/src/creative.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/common/src/integrations/prebid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl PrebidIntegration {
Err(_) => String::from_utf8(body_bytes).unwrap_or_else(|_| "".to_string()),
};

let rewritten = creative::rewrite_creative_html(&html, settings);
let rewritten = creative::rewrite_creative_html(settings, &html);

Ok(Response::from_status(StatusCode::OK)
.with_header(header::CONTENT_TYPE, "text/html; charset=utf-8")
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ fn finalize_proxied_response(
if ct.contains("text/html") {
// HTML: rewrite and serve as HTML (safe to read as string)
let body = beresp.take_body_str();
let rewritten = crate::creative::rewrite_creative_html(&body, settings);
let rewritten = crate::creative::rewrite_creative_html(settings, &body);
return rebuild_text_response(beresp, "text/html; charset=utf-8", rewritten);
}

if ct.contains("text/css") {
// CSS: rewrite url(...) references in stylesheets (safe to read as string)
let body = beresp.take_body_str();
let rewritten = crate::creative::rewrite_css_body(&body, settings);
let rewritten = crate::creative::rewrite_css_body(settings, &body);
return rebuild_text_response(beresp, "text/css; charset=utf-8", rewritten);
}

Expand Down Expand Up @@ -681,7 +681,7 @@ pub async fn handle_first_party_proxy_sign(
.unwrap_or_else(|| "https".to_string());
format!("{}:{}", default_scheme, trimmed)
} else {
crate::creative::to_abs(trimmed, settings).ok_or_else(|| {
crate::creative::to_abs(settings, trimmed).ok_or_else(|| {
Report::new(TrustedServerError::Proxy {
message: "unsupported url".to_string(),
})
Expand Down Expand Up @@ -1423,7 +1423,7 @@ mod tests {
.unwrap_or("")
.to_string();
assert!(ct_pre.contains("text/html"), "ct_pre={}", ct_pre);
let direct = creative::rewrite_creative_html(html, &settings);
let direct = creative::rewrite_creative_html(&settings, html);
assert!(direct.contains("/first-party/proxy?tsurl="), "{}", direct);
let req = Request::new(Method::GET, "https://edge.example/first-party/proxy");
let out = finalize(&settings, &req, "https://cdn.example/a.png", beresp);
Expand Down
5 changes: 1 addition & 4 deletions crates/common/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ fn detect_request_scheme(req: &Request) -> String {

/// Unified tsjs static serving: `/static/tsjs=<filename>`
/// Accepts: `tsjs-core(.min).js`, `tsjs-ext(.min).js`, `tsjs-creative(.min).js`
pub fn handle_tsjs_dynamic(
_settings: &Settings,
req: Request,
) -> Result<Response, Report<TrustedServerError>> {
pub fn handle_tsjs_dynamic(req: Request) -> Result<Response, Report<TrustedServerError>> {
const PREFIX: &str = "/static/tsjs=";
let path = req.get_path();
if !path.starts_with(PREFIX) {
Expand Down
4 changes: 1 addition & 3 deletions crates/fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ async fn route_request(
// Match known routes and handle them
let result = match (method, path.as_str()) {
// Serve the tsjs library
(Method::GET, path) if path.starts_with("/static/tsjs=") => {
handle_tsjs_dynamic(&settings, req)
}
(Method::GET, path) if path.starts_with("/static/tsjs=") => handle_tsjs_dynamic(req),

// Discovery endpoint for trusted-server capabilities and JWKS
(Method::GET, "/.well-known/trusted-server.json") => {
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/creative-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ log::debug!("creative: skipped non-network scheme {}", url);

```rust
let original = "<img src=\"https://tracker.com/pixel.gif\">";
let rewritten = rewrite_creative_html(original, &settings);
let rewritten = rewrite_creative_html(&settings, original);
assert!(rewritten.contains("/first-party/proxy"));
```

Expand All @@ -713,7 +713,7 @@ assert!(rewritten.contains("/first-party/proxy"));
#[test]
fn test_image_src_rewrite() {
let html = r#"<img src="https://cdn.example.com/banner.jpg">"#;
let result = rewrite_creative_html(html, &test_settings());
let result = rewrite_creative_html(&test_settings(), html);
assert!(result.contains("/first-party/proxy?tsurl="));
assert!(result.contains("&tstoken="));
}
Expand Down