Honor workspace connection settings in CLI sends (#537)

This commit is contained in:
Gregory Schier
2026-08-14 10:38:47 -07:00
committed by GitHub
parent 912aaeb7a7
commit d3055c64b3
6 changed files with 29 additions and 44 deletions
+1 -1
View File
@@ -585,7 +585,7 @@ async fn send_http_request_by_id(
encryption_manager: ctx.encryption_manager.clone(), encryption_manager: ctx.encryption_manager.clone(),
plugin_context: &plugin_context, plugin_context: &plugin_context,
cancelled_rx: None, cancelled_rx: None,
connection_manager: None, connection_manager: ctx.connection_manager(),
}) })
.await; .await;
+8
View File
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
use yaak_http::manager::HttpConnectionManager;
use yaak_models::blob_manager::BlobManager; use yaak_models::blob_manager::BlobManager;
use yaak_models::client_db::ClientDb; use yaak_models::client_db::ClientDb;
use yaak_models::query_manager::QueryManager; use yaak_models::query_manager::QueryManager;
@@ -31,6 +32,7 @@ pub struct CliContext {
query_manager: QueryManager, query_manager: QueryManager,
blob_manager: BlobManager, blob_manager: BlobManager,
pub encryption_manager: Arc<EncryptionManager>, pub encryption_manager: Arc<EncryptionManager>,
connection_manager: Arc<HttpConnectionManager>,
plugin_manager: Option<Arc<PluginManager>>, plugin_manager: Option<Arc<PluginManager>>,
plugin_event_bridge: Mutex<Option<CliPluginEventBridge>>, plugin_event_bridge: Mutex<Option<CliPluginEventBridge>>,
} }
@@ -54,6 +56,7 @@ impl CliContext {
query_manager, query_manager,
blob_manager, blob_manager,
encryption_manager, encryption_manager,
connection_manager: Arc::new(HttpConnectionManager::new()),
plugin_manager: None, plugin_manager: None,
plugin_event_bridge: Mutex::new(None), plugin_event_bridge: Mutex::new(None),
} }
@@ -91,6 +94,7 @@ impl CliContext {
self.query_manager.clone(), self.query_manager.clone(),
self.blob_manager.clone(), self.blob_manager.clone(),
self.encryption_manager.clone(), self.encryption_manager.clone(),
self.connection_manager.clone(),
self.data_dir.clone(), self.data_dir.clone(),
execution_context, execution_context,
) )
@@ -120,6 +124,10 @@ impl CliContext {
&self.blob_manager &self.blob_manager
} }
pub fn connection_manager(&self) -> &HttpConnectionManager {
&self.connection_manager
}
pub fn plugin_manager(&self) -> Arc<PluginManager> { pub fn plugin_manager(&self) -> Arc<PluginManager> {
self.plugin_manager.clone().expect("Plugin manager was not initialized for this command") self.plugin_manager.clone().expect("Plugin manager was not initialized for this command")
} }
+5 -1
View File
@@ -15,6 +15,7 @@ use yaak::render::{render_grpc_request, render_http_request};
use yaak::send::{SendHttpRequestWithPluginsParams, send_http_request_with_plugins}; use yaak::send::{SendHttpRequestWithPluginsParams, send_http_request_with_plugins};
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
use yaak_http::cookies::get_cookie_value_from_jar; use yaak_http::cookies::get_cookie_value_from_jar;
use yaak_http::manager::HttpConnectionManager;
use yaak_models::blob_manager::BlobManager; use yaak_models::blob_manager::BlobManager;
use yaak_models::models::Environment; use yaak_models::models::Environment;
use yaak_models::queries::any_request::AnyRequest; use yaak_models::queries::any_request::AnyRequest;
@@ -42,6 +43,7 @@ struct CliHostContext {
blob_manager: BlobManager, blob_manager: BlobManager,
plugin_manager: Arc<PluginManager>, plugin_manager: Arc<PluginManager>,
encryption_manager: Arc<EncryptionManager>, encryption_manager: Arc<EncryptionManager>,
connection_manager: Arc<HttpConnectionManager>,
response_dir: PathBuf, response_dir: PathBuf,
execution_context: CliExecutionContext, execution_context: CliExecutionContext,
} }
@@ -52,6 +54,7 @@ impl CliPluginEventBridge {
query_manager: QueryManager, query_manager: QueryManager,
blob_manager: BlobManager, blob_manager: BlobManager,
encryption_manager: Arc<EncryptionManager>, encryption_manager: Arc<EncryptionManager>,
connection_manager: Arc<HttpConnectionManager>,
data_dir: PathBuf, data_dir: PathBuf,
execution_context: CliExecutionContext, execution_context: CliExecutionContext,
) -> Self { ) -> Self {
@@ -63,6 +66,7 @@ impl CliPluginEventBridge {
blob_manager, blob_manager,
plugin_manager, plugin_manager,
encryption_manager, encryption_manager,
connection_manager,
response_dir: data_dir.join("responses"), response_dir: data_dir.join("responses"),
execution_context, execution_context,
}); });
@@ -214,7 +218,7 @@ async fn build_plugin_reply(
encryption_manager: host_context.encryption_manager.clone(), encryption_manager: host_context.encryption_manager.clone(),
plugin_context: &plugin_context, plugin_context: &plugin_context,
cancelled_rx: None, cancelled_rx: None,
connection_manager: None, connection_manager: &host_context.connection_manager,
}) })
.await .await
{ {
@@ -160,7 +160,7 @@ async fn send_http_request_inner<R: Runtime>(
encryption_manager, encryption_manager,
plugin_context, plugin_context,
cancelled_rx: Some(cancelled_rx.clone()), cancelled_rx: Some(cancelled_rx.clone()),
connection_manager: Some(connection_manager.inner()), connection_manager: connection_manager.inner(),
}) })
.await .await
.map_err(|e| GenericError(e.to_string()))?; .map_err(|e| GenericError(e.to_string()))?;
+13 -40
View File
@@ -127,31 +127,6 @@ pub struct CookieBehavior {
pub store_cookies: bool, pub store_cookies: bool,
} }
struct DefaultSendRequestExecutor;
#[async_trait]
impl SendRequestExecutor for DefaultSendRequestExecutor {
async fn send(
&self,
sendable_request: SendableHttpRequest,
event_tx: mpsc::Sender<SenderHttpResponseEvent>,
cookie_behavior: CookieBehavior,
) -> yaak_http::error::Result<yaak_http::sender::HttpResponse> {
let sender = ReqwestSender::new()?;
let transaction = match cookie_behavior.store {
Some(store) => HttpTransaction::with_cookie_behavior(
sender,
store,
cookie_behavior.send_cookies,
cookie_behavior.store_cookies,
),
None => HttpTransaction::new(sender),
};
let (_cancel_tx, cancel_rx) = watch::channel(false);
transaction.execute_with_cancellation(sendable_request, cancel_rx, event_tx).await
}
}
struct PluginPrepareSendableRequest { struct PluginPrepareSendableRequest {
plugin_manager: Arc<PluginManager>, plugin_manager: Arc<PluginManager>,
plugin_context: PluginContext, plugin_context: PluginContext,
@@ -259,7 +234,7 @@ pub struct SendHttpRequestByIdParams<'a, T: TemplateCallback> {
pub emit_response_body_chunks_to: Option<mpsc::UnboundedSender<Vec<u8>>>, pub emit_response_body_chunks_to: Option<mpsc::UnboundedSender<Vec<u8>>>,
pub cancelled_rx: Option<watch::Receiver<bool>>, pub cancelled_rx: Option<watch::Receiver<bool>>,
pub prepare_sendable_request: Option<&'a dyn PrepareSendableRequest>, pub prepare_sendable_request: Option<&'a dyn PrepareSendableRequest>,
pub executor: Option<&'a dyn SendRequestExecutor>, pub executor: &'a dyn SendRequestExecutor,
} }
pub struct SendHttpRequestParams<'a, T: TemplateCallback> { pub struct SendHttpRequestParams<'a, T: TemplateCallback> {
@@ -278,7 +253,7 @@ pub struct SendHttpRequestParams<'a, T: TemplateCallback> {
pub auth_context_id: Option<String>, pub auth_context_id: Option<String>,
pub existing_response: Option<HttpResponse>, pub existing_response: Option<HttpResponse>,
pub prepare_sendable_request: Option<&'a dyn PrepareSendableRequest>, pub prepare_sendable_request: Option<&'a dyn PrepareSendableRequest>,
pub executor: Option<&'a dyn SendRequestExecutor>, pub executor: &'a dyn SendRequestExecutor,
} }
pub struct SendHttpRequestWithPluginsParams<'a> { pub struct SendHttpRequestWithPluginsParams<'a> {
@@ -296,7 +271,7 @@ pub struct SendHttpRequestWithPluginsParams<'a> {
pub encryption_manager: Arc<EncryptionManager>, pub encryption_manager: Arc<EncryptionManager>,
pub plugin_context: &'a PluginContext, pub plugin_context: &'a PluginContext,
pub cancelled_rx: Option<watch::Receiver<bool>>, pub cancelled_rx: Option<watch::Receiver<bool>>,
pub connection_manager: Option<&'a HttpConnectionManager>, pub connection_manager: &'a HttpConnectionManager,
} }
pub struct SendHttpRequestByIdWithPluginsParams<'a> { pub struct SendHttpRequestByIdWithPluginsParams<'a> {
@@ -313,7 +288,7 @@ pub struct SendHttpRequestByIdWithPluginsParams<'a> {
pub encryption_manager: Arc<EncryptionManager>, pub encryption_manager: Arc<EncryptionManager>,
pub plugin_context: &'a PluginContext, pub plugin_context: &'a PluginContext,
pub cancelled_rx: Option<watch::Receiver<bool>>, pub cancelled_rx: Option<watch::Receiver<bool>>,
pub connection_manager: Option<&'a HttpConnectionManager>, pub connection_manager: &'a HttpConnectionManager,
} }
pub struct SendHttpRequestResult { pub struct SendHttpRequestResult {
@@ -403,14 +378,13 @@ pub async fn send_http_request_with_plugins(
plugin_context: params.plugin_context.clone(), plugin_context: params.plugin_context.clone(),
cancelled_rx: params.cancelled_rx.clone(), cancelled_rx: params.cancelled_rx.clone(),
}; };
let executor = let executor = ConnectionManagerSendRequestExecutor {
params.connection_manager.map(|connection_manager| ConnectionManagerSendRequestExecutor { connection_manager: params.connection_manager,
connection_manager, plugin_context_id: params.plugin_context.id.clone(),
plugin_context_id: params.plugin_context.id.clone(), query_manager: params.query_manager.clone(),
query_manager: params.query_manager.clone(), request: params.request.clone(),
request: params.request.clone(), cancelled_rx: params.cancelled_rx.clone(),
cancelled_rx: params.cancelled_rx.clone(), };
});
send_http_request(SendHttpRequestParams { send_http_request(SendHttpRequestParams {
query_manager: params.query_manager, query_manager: params.query_manager,
@@ -428,7 +402,7 @@ pub async fn send_http_request_with_plugins(
auth_context_id: None, auth_context_id: None,
existing_response: params.existing_response, existing_response: params.existing_response,
prepare_sendable_request: Some(&auth_hook), prepare_sendable_request: Some(&auth_hook),
executor: executor.as_ref().map(|e| e as &dyn SendRequestExecutor), executor: &executor,
}) })
.await .await
} }
@@ -613,8 +587,7 @@ pub async fn send_http_request<T: TemplateCallback>(
} }
}); });
let default_executor = DefaultSendRequestExecutor; let executor = params.executor;
let executor = params.executor.unwrap_or(&default_executor);
let started_at = Instant::now(); let started_at = Instant::now();
let request_started_url = sendable_request.url.clone(); let request_started_url = sendable_request.url.clone();
+1 -1
View File
@@ -83,7 +83,7 @@
"@tauri-apps/cli": "npm:@tauri-apps/cli-cef@3.0.0-alpha.6", "@tauri-apps/cli": "npm:@tauri-apps/cli-cef@3.0.0-alpha.6",
"@types/babel__core": "^7.20.5", "@types/babel__core": "^7.20.5",
"@vitejs/plugin-react": "^6.0.1", "@vitejs/plugin-react": "^6.0.1",
"@yaakapp/cli": "*", "@yaakapp/cli": "latest",
"babel-plugin-react-compiler": "^1.0.0", "babel-plugin-react-compiler": "^1.0.0",
"dotenv-cli": "^11.0.0", "dotenv-cli": "^11.0.0",
"nodejs-file-downloader": "^4.13.0", "nodejs-file-downloader": "^4.13.0",