@@ -6,7 +6,6 @@ use std::rc::Rc;
66
77use lol_html:: { element, html_content:: ContentType , Settings as RewriterSettings } ;
88
9- use crate :: geo:: GeoInfo ;
109use crate :: settings:: Settings ;
1110use crate :: streaming_processor:: { HtmlRewriterAdapter , StreamProcessor } ;
1211use 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
2422impl 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
0 commit comments