Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(fetch): separate manual hop lookup from transport redirect limits
ldm03b35e5fa0fa0
diff --git a/moli-fetch/src/blocking/cache.rs b/moli-fetch/src/blocking/cache.rsindex 34a19cddf..40745ad34 100644--- a/moli-fetch/src/blocking/cache.rs+++ b/moli-fetch/src/blocking/cache.rs@@ -154,7 +154,16 @@ pub(crate) fn next_followed_redirect_url_from_parts(.validate_cors_response_for_url(final_url, headers).map_err(anyhow::Error::msg)?;}- let next_url = next_redirect_url_from_parts(final_url, status, headers, redirect_count)?;+ // A browser may follow redirects itself, preserving the full URL list for+ // CORS and Fetch Metadata while asking this transport for only one hop.+ // Only automatically followed transport requests consume this layer's limit.+ let transport_redirect_count = if request.follow_redirects {+ redirect_count+ } else {+ 0+ };+ let next_url =+ next_redirect_url_from_parts(final_url, status, headers, transport_redirect_count)?;if request.follow_redirects&& let Some(next_url) = next_url.as_ref(){@@ -208,6 +217,60 @@ mod tests {Ok(())}+ #[test]+ fn browser_followed_hops_preserve_cors_without_reapplying_transport_redirect_limit()+ -> Result<()> {+ let origin_url = Url::parse("https://origin.test/page")?;+ let current = Url::parse("https://other.test/redirect")?;+ let request = Request::new_browser(+ "GET",+ current.clone(),+ None,+ Vec::new(),+ moli_url::WebOrigin::from_url(&origin_url),+ )+ .with_follow_redirects(false);+ let headers = vec![+ ("location".to_owned(), b"/next".to_vec()),+ (+ "access-control-allow-origin".to_owned(),+ b"https://origin.test".to_vec(),+ ),+ (+ "access-control-allow-credentials".to_owned(),+ b"true".to_vec(),+ ),+ ];+ let next = next_followed_redirect_url_from_parts(+ &request,+ ¤t,+ 302,+ &headers,+ super::super::MAX_REDIRECTS,+ )?;+ assert_eq!(next, Some(current.join("/next")?));+ let automatic = request.clone().with_follow_redirects(true);+ let error = next_followed_redirect_url_from_parts(+ &automatic,+ ¤t,+ 302,+ &headers,+ super::super::MAX_REDIRECTS,+ )+ .expect_err("automatically followed transport requests retain their redirect limit");+ assert!(error.to_string().contains("redirect limit exceeded"));+ let denied = next_followed_redirect_url_from_parts(+ &request,+ ¤t,+ 302,+ &headers[..1],+ super::super::MAX_REDIRECTS,+ )+ .expect_err("a manually followed browser hop still requires CORS permission");+ assert!(denied.to_string().contains("CORS"));+ Ok(())+ }+#[test]fn cache_key_includes_network_partition_key() -> Result<()> {let request_url = Url::parse("https://cdn.example.test/app.css")?;