From dad9cebb9e1b95016f0a50f626d40a209de4abb5 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 12 May 2025 16:57:13 -0700 Subject: [PATCH] Don't send empty ? for ws query params --- src-tauri/yaak-ws/src/commands.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src-tauri/yaak-ws/src/commands.rs b/src-tauri/yaak-ws/src/commands.rs index 25c5d2ea..c1de4f80 100644 --- a/src-tauri/yaak-ws/src/commands.rs +++ b/src-tauri/yaak-ws/src/commands.rs @@ -5,15 +5,15 @@ use log::{info, warn}; use std::str::FromStr; use tauri::http::{HeaderMap, HeaderName}; use tauri::{AppHandle, Runtime, State, Url, WebviewWindow}; -use tokio::sync::{mpsc, Mutex}; -use tokio_tungstenite::tungstenite::http::HeaderValue; +use tokio::sync::{Mutex, mpsc}; use tokio_tungstenite::tungstenite::Message; +use tokio_tungstenite::tungstenite::http::HeaderValue; use yaak_http::apply_path_placeholders; -use yaak_models::query_manager::QueryManagerExt; use yaak_models::models::{ HttpResponseHeader, WebsocketConnection, WebsocketConnectionState, WebsocketEvent, WebsocketEventType, WebsocketRequest, }; +use yaak_models::query_manager::QueryManagerExt; use yaak_models::util::UpdateSource; use yaak_plugins::events::{ CallHttpAuthenticationRequest, HttpHeader, PluginWindowContext, RenderPurpose, @@ -257,12 +257,16 @@ pub(crate) async fn connect( // Add URL parameters to URL let mut url = Url::parse(&url).unwrap(); { - let mut query_pairs = url.query_pairs_mut(); - for p in url_parameters.clone() { - if !p.enabled || p.name.is_empty() { - continue; + let valid_query_pairs = url_parameters + .into_iter() + .filter(|p| p.enabled && !p.name.is_empty()) + .collect::>(); + // NOTE: Only mutate query pairs if there are any, or it will append an empty `?` to the URL + if !valid_query_pairs.is_empty() { + let mut query_pairs = url.query_pairs_mut(); + for p in valid_query_pairs { + query_pairs.append_pair(p.name.as_str(), p.value.as_str()); } - query_pairs.append_pair(p.name.as_str(), p.value.as_str()); } }