diff --git a/Cargo.lock b/Cargo.lock index 68b85b8..37e4ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1764,6 +1764,7 @@ dependencies = [ "async-tungstenite", "blocking", "bstr", + "form_urlencoded", "futures", "futures-lite", "futures-rustls", diff --git a/crates/lune-std-net/Cargo.toml b/crates/lune-std-net/Cargo.toml index c56080b..94aa369 100644 --- a/crates/lune-std-net/Cargo.toml +++ b/crates/lune-std-net/Cargo.toml @@ -24,6 +24,7 @@ async-net = "2.0" async-tungstenite = "0.29" blocking = "1.6" bstr = "1.9" +form_urlencoded = "1.2" futures = { version = "0.3", default-features = false, features = ["std"] } futures-lite = "2.6" futures-rustls = "0.26" diff --git a/crates/lune-std-net/src/client/mod.rs b/crates/lune-std-net/src/client/mod.rs index 9fbcbd4..e67a8e1 100644 --- a/crates/lune-std-net/src/client/mod.rs +++ b/crates/lune-std-net/src/client/mod.rs @@ -47,7 +47,7 @@ pub async fn send_request(mut request: Request, lua: Lua) -> LuaResult .uri() .to_string() .parse::() - .expect("uri is valid"); + .into_lua_err()?; // Some headers are required by most if not // all servers, make sure those are present... diff --git a/crates/lune-std-net/src/shared/request.rs b/crates/lune-std-net/src/shared/request.rs index f6212e1..911018e 100644 --- a/crates/lune-std-net/src/shared/request.rs +++ b/crates/lune-std-net/src/shared/request.rs @@ -110,15 +110,18 @@ impl Request { */ pub fn query(&self) -> HashMap> { let uri = self.inner.uri(); - let url = uri.to_string().parse::().expect("uri is valid"); let mut result = HashMap::>::new(); - for (key, value) in url.query_pairs() { - result - .entry(key.into_owned()) - .or_default() - .push(value.into_owned()); + + if let Some(query) = uri.query() { + for (key, value) in form_urlencoded::parse(query.as_bytes()) { + result + .entry(key.to_string()) + .or_default() + .push(value.to_string()); + } } + result }