fix query paris
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -58,32 +58,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fs::create_dir_all(&session_dir)?;
|
||||
info!("Created session directory: {}", session_dir.display());
|
||||
|
||||
// Parse extra query params once if specified
|
||||
let extra_params: Vec<(String, String)> = args
|
||||
.query_string_all
|
||||
.as_ref()
|
||||
.map(|qs| {
|
||||
form_urlencoded::parse(qs.as_bytes())
|
||||
.map(|(k, v)| (k.into_owned(), v.into_owned()))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
// Process URLs and add query string parameters if specified
|
||||
let mut processed_urls = Vec::new();
|
||||
for url_str in &args.urls {
|
||||
let mut url = Url::parse(url_str)?;
|
||||
|
||||
if let Some(ref extra_params) = args.query_string_all {
|
||||
// Parse existing query string and extra params
|
||||
if !extra_params.is_empty() {
|
||||
let existing: Vec<(String, String)> = url
|
||||
.query_pairs()
|
||||
.map(|(k, v)| (k.into_owned(), v.into_owned()))
|
||||
.collect();
|
||||
|
||||
let extra: Vec<(String, String)> = form_urlencoded::parse(extra_params.as_bytes())
|
||||
.map(|(k, v)| (k.into_owned(), v.into_owned()))
|
||||
.collect();
|
||||
|
||||
// Rebuild query string with existing + extra params
|
||||
{
|
||||
let mut query_pairs = url.query_pairs_mut();
|
||||
query_pairs.clear();
|
||||
for (k, v) in &existing {
|
||||
query_pairs.append_pair(k, v);
|
||||
}
|
||||
for (k, v) in &extra {
|
||||
query_pairs.append_pair(k, v);
|
||||
}
|
||||
let mut query_pairs = url.query_pairs_mut();
|
||||
query_pairs.clear();
|
||||
for (k, v) in &existing {
|
||||
query_pairs.append_pair(k, v);
|
||||
}
|
||||
for (k, v) in &extra_params {
|
||||
query_pairs.append_pair(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user