tauri_plugin_http/
lib.rs

1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5//! Access the HTTP client written in Rust.
6
7pub use reqwest;
8use tauri::{
9    plugin::{Builder, TauriPlugin},
10    Manager, Runtime,
11};
12
13pub use error::{Error, Result};
14
15mod commands;
16mod error;
17mod scope;
18
19pub(crate) struct Http {
20    #[cfg(feature = "cookies")]
21    cookies_jar: std::sync::Arc<reqwest::cookie::Jar>,
22}
23
24pub fn init<R: Runtime>() -> TauriPlugin<R> {
25    Builder::<R>::new("http")
26        .setup(|app, _| {
27            let state = Http {
28                #[cfg(feature = "cookies")]
29                cookies_jar: std::sync::Arc::new(reqwest::cookie::Jar::default()),
30            };
31
32            app.manage(state);
33
34            Ok(())
35        })
36        .invoke_handler(tauri::generate_handler![
37            commands::fetch,
38            commands::fetch_cancel,
39            commands::fetch_send
40        ])
41        .build()
42}