feat(http): enable cookies and set origin header (#1192)

This commit is contained in:
Amr Bashir
2024-05-14 01:39:36 +03:00
committed by GitHub
parent 463f5971eb
commit 58330f9ec1
5 changed files with 40 additions and 29 deletions
+14 -18
View File
@@ -9,7 +9,7 @@
pub use reqwest;
use tauri::{
plugin::{Builder, TauriPlugin},
AppHandle, Manager, Runtime,
Manager, Runtime,
};
pub use error::{Error, Result};
@@ -18,32 +18,28 @@ mod commands;
mod error;
mod scope;
struct Http<R: Runtime> {
#[allow(dead_code)]
app: AppHandle<R>,
pub(crate) struct Http {
#[cfg(feature = "cookies")]
cookies_jar: std::sync::Arc<reqwest::cookie::Jar>,
}
/* trait HttpExt<R: Runtime> {
fn http(&self) -> &Http<R>;
}
impl<R: Runtime, T: Manager<R>> HttpExt<R> for T {
fn http(&self) -> &Http<R> {
self.state::<Http<R>>().inner()
}
} */
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::<R>::new("http")
.setup(|app, _| {
let state = Http {
#[cfg(feature = "cookies")]
cookies_jar: std::sync::Arc::new(reqwest::cookie::Jar::default()),
};
app.manage(state);
Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::fetch,
commands::fetch_cancel,
commands::fetch_send,
commands::fetch_read_body,
])
.setup(|app, _api| {
app.manage(Http { app: app.clone() });
Ok(())
})
.build()
}