Skip to content

Commit 0095ea5

Browse files
cleanup
1 parent 0d9f302 commit 0095ea5

File tree

4 files changed

+3
-128
lines changed

4 files changed

+3
-128
lines changed

crates/common/src/html_processor.rs

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::rc::Rc;
66

77
use lol_html::{element, html_content::ContentType, Settings as RewriterSettings};
88

9-
use crate::geo::GeoInfo;
109
use crate::settings::Settings;
1110
use crate::streaming_processor::{HtmlRewriterAdapter, StreamProcessor};
1211
use crate::tsjs;
@@ -18,7 +17,6 @@ pub struct HtmlProcessorConfig {
1817
pub request_host: String,
1918
pub request_scheme: String,
2019
pub enable_prebid: bool,
21-
pub geo_info: Option<GeoInfo>,
2220
}
2321

2422
impl HtmlProcessorConfig {
@@ -28,28 +26,12 @@ impl HtmlProcessorConfig {
2826
origin_host: &str,
2927
request_host: &str,
3028
request_scheme: &str,
31-
geo_info: Option<GeoInfo>,
3229
) -> Self {
3330
Self {
3431
origin_host: origin_host.to_string(),
3532
request_host: request_host.to_string(),
3633
request_scheme: request_scheme.to_string(),
3734
enable_prebid: settings.prebid.auto_configure,
38-
geo_info,
39-
}
40-
}
41-
42-
/// Generate JavaScript code to inject geo data into the page
43-
fn geo_script_tag(geo_info: &GeoInfo) -> String {
44-
// Serialize to JSON and embed in script tag
45-
match serde_json::to_string(geo_info) {
46-
Ok(json) => {
47-
format!(r#"<script>window.__TS_GEO = {};</script>"#, json)
48-
}
49-
Err(e) => {
50-
log::error!("Failed to serialize geo info: {}", e);
51-
String::new()
52-
}
5335
}
5436
}
5537
}
@@ -105,20 +87,11 @@ pub fn create_html_processor(config: HtmlProcessorConfig) -> impl StreamProcesso
10587

10688
let rewriter_settings = RewriterSettings {
10789
element_content_handlers: vec![
108-
// Inject tsjs and geo data once at the start of <head>
90+
// Inject tsjs once at the start of <head>
10991
element!("head", {
11092
let injected_tsjs = injected_tsjs.clone();
111-
let geo_info = config.geo_info.clone();
11293
move |el| {
11394
if !injected_tsjs.get() {
114-
// Inject geo data first (if available)
115-
if let Some(ref geo) = geo_info {
116-
let geo_script = HtmlProcessorConfig::geo_script_tag(geo);
117-
if !geo_script.is_empty() {
118-
el.prepend(&geo_script, ContentType::Html);
119-
}
120-
}
121-
12295
// Then inject tsjs core script
12396
let loader = tsjs::core_script_tag();
12497
el.prepend(&loader, ContentType::Html);
@@ -266,19 +239,6 @@ mod tests {
266239
request_host: "test.example.com".to_string(),
267240
request_scheme: "https".to_string(),
268241
enable_prebid: false,
269-
geo_info: None,
270-
}
271-
}
272-
273-
fn create_test_geo_info() -> GeoInfo {
274-
GeoInfo {
275-
city: "San Francisco".to_string(),
276-
country: "US".to_string(),
277-
continent: "North America".to_string(),
278-
latitude: 37.7749,
279-
longitude: -122.4194,
280-
metro_code: 807,
281-
region: Some("CA".to_string()),
282242
}
283243
}
284244

@@ -400,7 +360,6 @@ mod tests {
400360
"origin.test-publisher.com",
401361
"proxy.example.com",
402362
"https",
403-
None,
404363
);
405364

406365
assert_eq!(config.origin_host, "origin.test-publisher.com");
@@ -409,67 +368,6 @@ mod tests {
409368
assert!(config.enable_prebid); // Uses default true
410369
}
411370

412-
#[test]
413-
fn test_geo_data_injection() {
414-
let html = r#"<html><head><title>Test</title></head><body>Content</body></html>"#;
415-
416-
let mut config = create_test_config();
417-
config.geo_info = Some(create_test_geo_info());
418-
419-
let processor = create_html_processor(config);
420-
let pipeline_config = PipelineConfig {
421-
input_compression: Compression::None,
422-
output_compression: Compression::None,
423-
chunk_size: 8192,
424-
};
425-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
426-
427-
let mut output = Vec::new();
428-
let result = pipeline.process(Cursor::new(html.as_bytes()), &mut output);
429-
assert!(result.is_ok());
430-
431-
let processed = String::from_utf8_lossy(&output);
432-
433-
// Check that geo data was injected
434-
assert!(processed.contains("window.__trustedServerGeo"));
435-
assert!(processed.contains(r#""city":"San Francisco""#));
436-
assert!(processed.contains(r#""country":"US""#));
437-
assert!(processed.contains(r#""latitude":37.7749"#));
438-
assert!(processed.contains(r#""longitude":-122.4194"#));
439-
assert!(processed.contains(r#""metro_code":807"#));
440-
assert!(processed.contains(r#""region":"CA""#));
441-
442-
// Verify tsjs was still injected
443-
assert!(processed.contains("/static/tsjs=tsjs-core.min.js"));
444-
}
445-
446-
#[test]
447-
fn test_no_geo_data_when_none() {
448-
let html = r#"<html><head><title>Test</title></head><body>Content</body></html>"#;
449-
450-
let config = create_test_config(); // geo_info is None
451-
452-
let processor = create_html_processor(config);
453-
let pipeline_config = PipelineConfig {
454-
input_compression: Compression::None,
455-
output_compression: Compression::None,
456-
chunk_size: 8192,
457-
};
458-
let mut pipeline = StreamingPipeline::new(pipeline_config, processor);
459-
460-
let mut output = Vec::new();
461-
let result = pipeline.process(Cursor::new(html.as_bytes()), &mut output);
462-
assert!(result.is_ok());
463-
464-
let processed = String::from_utf8_lossy(&output);
465-
466-
// Should not contain geo data when none provided
467-
assert!(!processed.contains("window.__trustedServerGeo"));
468-
469-
// But tsjs should still be injected
470-
assert!(processed.contains("/static/tsjs=tsjs-core.min.js"));
471-
}
472-
473371
#[test]
474372
fn test_real_publisher_html() {
475373
// Test with publisher HTML from test_publisher.html

crates/common/src/publisher.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::http_util::serve_static_with_etag;
88
use crate::constants::{HEADER_SYNTHETIC_TRUSTED_SERVER, HEADER_X_COMPRESS_HINT};
99
use crate::cookies::create_synthetic_cookie;
1010
use crate::error::TrustedServerError;
11-
use crate::geo::GeoInfo;
1211
use crate::settings::Settings;
1312
use crate::streaming_processor::{Compression, PipelineConfig, StreamProcessor, StreamingPipeline};
1413
use crate::streaming_replacer::create_url_replacer;
@@ -106,7 +105,6 @@ struct ProcessResponseParams<'a> {
106105
request_scheme: &'a str,
107106
settings: &'a Settings,
108107
content_type: &'a str,
109-
geo_info: Option<GeoInfo>,
110108
}
111109

112110
/// Process response body in streaming fashion with compression preservation
@@ -131,7 +129,6 @@ fn process_response_streaming(
131129
params.request_host,
132130
params.request_scheme,
133131
params.settings,
134-
params.geo_info,
135132
)?;
136133

137134
let config = PipelineConfig {
@@ -174,16 +171,14 @@ fn create_html_stream_processor(
174171
request_host: &str,
175172
request_scheme: &str,
176173
settings: &Settings,
177-
geo_info: Option<GeoInfo>,
178174
) -> Result<impl StreamProcessor, Report<TrustedServerError>> {
179175
use crate::html_processor::{create_html_processor, HtmlProcessorConfig};
180176

181177
let config = HtmlProcessorConfig::from_settings(
182178
settings,
183179
origin_host,
184180
request_host,
185-
request_scheme,
186-
geo_info,
181+
request_scheme
187182
);
188183

189184
Ok(create_html_processor(config))
@@ -232,17 +227,6 @@ pub fn handle_publisher_request(
232227

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

235-
// Extract geo information from the request
236-
let geo_info = GeoInfo::from_request(&req);
237-
if let Some(ref geo) = geo_info {
238-
log::info!(
239-
"Geo info: city={}, country={}, metro_code={}",
240-
geo.city,
241-
geo.country,
242-
geo.metro_code
243-
);
244-
}
245-
246230
// Generate synthetic identifiers before the request body is consumed.
247231
let synthetic_id = get_or_generate_synthetic_id(settings, &req)?;
248232
let has_synthetic_cookie = req
@@ -320,7 +304,6 @@ pub fn handle_publisher_request(
320304
request_scheme: &request_scheme,
321305
settings,
322306
content_type: &content_type,
323-
geo_info: geo_info.clone(),
324307
};
325308
match process_response_streaming(body, params) {
326309
Ok(processed_body) => {

crates/js/lib/src/geo/index.ts

Whitespace-only changes.

crates/js/lib/vite.config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { defineConfig } from 'vite';
44
import type { Plugin } from 'vite';
55

6-
type BundleName = 'core' | 'ext' | 'creative' | 'geo';
6+
type BundleName = 'core' | 'ext' | 'creative';
77

88
type BundleConfig = {
99
input: string;
@@ -29,12 +29,6 @@ const BUNDLES: Record<BundleName, BundleConfig> = {
2929
fileName: 'tsjs-creative.js',
3030
name: 'tscreative',
3131
},
32-
33-
geo: {
34-
input: path.resolve(__dirname, 'src/geo/index.ts'),
35-
fileName: 'tsjs-geo.js',
36-
name: 'tscreative',
37-
},
3832
};
3933

4034
function resolveBundleName(mode: string | undefined): BundleName {

0 commit comments

Comments
 (0)