mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-18 21:12:19 +02:00
feat(http): enable cookies and set origin header (#1192)
This commit is contained in:
+14
-18
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user