diff --git a/crates/common/src/html_processor.rs b/crates/common/src/html_processor.rs
index f786c78..b91bb9e 100644
--- a/crates/common/src/html_processor.rs
+++ b/crates/common/src/html_processor.rs
@@ -5,7 +5,6 @@ use std::cell::Cell;
use std::rc::Rc;
use lol_html::{element, html_content::ContentType, text, Settings as RewriterSettings};
-use regex::Regex;
use crate::integrations::{
AttributeRewriteOutcome, IntegrationAttributeContext, IntegrationRegistry,
@@ -22,14 +21,12 @@ pub struct HtmlProcessorConfig {
pub request_host: String,
pub request_scheme: String,
pub integrations: IntegrationRegistry,
- pub nextjs_enabled: bool,
- pub nextjs_attributes: Vec,
}
impl HtmlProcessorConfig {
/// Create from settings and request parameters
pub fn from_settings(
- settings: &Settings,
+ _settings: &Settings,
integrations: &IntegrationRegistry,
origin_host: &str,
request_host: &str,
@@ -40,8 +37,6 @@ impl HtmlProcessorConfig {
request_host: request_host.to_string(),
request_scheme: request_scheme.to_string(),
integrations: integrations.clone(),
- nextjs_enabled: settings.publisher.nextjs.enabled,
- nextjs_attributes: settings.publisher.nextjs.rewrite_attributes.clone(),
}
}
}
@@ -75,39 +70,6 @@ pub fn create_html_processor(config: HtmlProcessorConfig) -> impl StreamProcesso
fn protocol_relative_replacement(&self) -> String {
format!("//{}", self.request_host)
}
-
- fn rewrite_nextjs_values(&self, content: &str, attributes: &[String]) -> Option {
- let mut rewritten = content.to_string();
- let mut changed = false;
- let escaped_origin = regex::escape(&self.origin_host);
- for attribute in attributes {
- let escaped_attr = regex::escape(attribute);
- let pattern = format!(
- r#"(?P(?:\\*")?{attr}(?:\\*")?:\\*")(?Phttps?://|//){origin}"#,
- attr = escaped_attr,
- origin = escaped_origin
- );
- let regex = Regex::new(&pattern).expect("valid Next.js rewrite regex");
- let new_value = regex.replace_all(&rewritten, |caps: ®ex::Captures| {
- let scheme = &caps["scheme"];
- let replacement = if scheme == "//" {
- format!("//{}", self.request_host)
- } else {
- self.replacement_url()
- };
- format!("{}{}", &caps["prefix"], replacement)
- });
- if new_value != rewritten {
- changed = true;
- rewritten = new_value.into_owned();
- }
- }
- if changed {
- Some(rewritten)
- } else {
- None
- }
- }
}
let patterns = Rc::new(UrlPatterns {
@@ -116,8 +78,6 @@ pub fn create_html_processor(config: HtmlProcessorConfig) -> impl StreamProcesso
request_scheme: config.request_scheme.clone(),
});
- let nextjs_attributes = Rc::new(config.nextjs_attributes.clone());
-
let injected_tsjs = Rc::new(Cell::new(false));
let integration_registry = config.integrations.clone();
let script_rewriters = integration_registry.script_rewriters();
@@ -378,35 +338,6 @@ pub fn create_html_processor(config: HtmlProcessorConfig) -> impl StreamProcesso
}));
}
- if config.nextjs_enabled && !nextjs_attributes.is_empty() {
- element_content_handlers.push(text!("script#__NEXT_DATA__", {
- let patterns = patterns.clone();
- let attributes = nextjs_attributes.clone();
- move |text| {
- let content = text.as_str();
- if let Some(rewritten) = patterns.rewrite_nextjs_values(content, &attributes) {
- text.replace(&rewritten, ContentType::Text);
- }
- Ok(())
- }
- }));
-
- element_content_handlers.push(text!("script", {
- let patterns = patterns.clone();
- let attributes = nextjs_attributes.clone();
- move |text| {
- let content = text.as_str();
- if !content.contains("self.__next_f") {
- return Ok(());
- }
- if let Some(rewritten) = patterns.rewrite_nextjs_values(content, &attributes) {
- text.replace(&rewritten, ContentType::Text);
- }
- Ok(())
- }
- }));
- }
-
let rewriter_settings = RewriterSettings {
element_content_handlers,
..RewriterSettings::default()
@@ -433,8 +364,6 @@ mod tests {
request_host: "test.example.com".to_string(),
request_scheme: "https".to_string(),
integrations: IntegrationRegistry::default(),
- nextjs_enabled: false,
- nextjs_attributes: vec!["href".to_string(), "link".to_string(), "url".to_string()],
}
}
@@ -605,9 +534,19 @@ mod tests {