diff --git a/packages/blitz-net/src/lib.rs b/packages/blitz-net/src/lib.rs index 478eeb83..72357ab5 100644 --- a/packages/blitz-net/src/lib.rs +++ b/packages/blitz-net/src/lib.rs @@ -10,6 +10,18 @@ use tokio::{ const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"; +pub async fn get_text(url: &str) -> String { + Client::new() + .get(url) + .header("User-Agent", USER_AGENT) + .send() + .await + .unwrap() + .text() + .await + .unwrap() +} + pub struct Provider { rt: Handle, client: Client, diff --git a/packages/blitz/Cargo.toml b/packages/blitz/Cargo.toml index 70637444..2cd7268b 100644 --- a/packages/blitz/Cargo.toml +++ b/packages/blitz/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [features] default = ["net", "accessibility", "menu", "tracing", "svg"] svg = ["blitz-renderer-vello/svg"] -net = ["dep:tokio", "dep:reqwest", "dep:url", "dep:blitz-net"] +net = ["dep:tokio", "dep:url", "dep:blitz-net"] accessibility = ["blitz-shell/accessibility"] menu = ["blitz-shell/menu"] tracing = ["blitz-shell/tracing"] @@ -22,7 +22,6 @@ blitz-net = { path = "../blitz-net", optional = true } # IO & Networking url = { workspace = true, features = ["serde"], optional = true } tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } -reqwest = { workspace = true, optional = true } [package.metadata.docs.rs] all-features = true diff --git a/packages/blitz/src/lib.rs b/packages/blitz/src/lib.rs index 01ec03d2..5a56cc49 100644 --- a/packages/blitz/src/lib.rs +++ b/packages/blitz/src/lib.rs @@ -18,15 +18,10 @@ use blitz_shell::{ #[cfg(feature = "net")] pub fn launch_url(url: &str) { - use reqwest::Client; - use url::Url; - - const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"; - println!("{}", url); - // Assert that url is valid + println!("{}", url); let url = url.to_owned(); - Url::parse(&url).expect("Invalid url"); + url::Url::parse(&url).expect("Invalid url"); // Turn on the runtime and enter it let rt = tokio::runtime::Builder::new_multi_thread() @@ -35,18 +30,7 @@ pub fn launch_url(url: &str) { .unwrap(); let _guard = rt.enter(); - let client = Client::new(); - let html = rt.block_on(async { - client - .get(&url) - .header("User-Agent", USER_AGENT) - .send() - .await - .unwrap() - .text() - .await - .unwrap() - }); + let html = rt.block_on(blitz_net::get_text(&url)); launch_internal( &html,