diff --git a/core/tauri-runtime/src/window.rs b/core/tauri-runtime/src/window.rs index c5e4fb500575..95c69e894fab 100644 --- a/core/tauri-runtime/src/window.rs +++ b/core/tauri-runtime/src/window.rs @@ -9,7 +9,6 @@ use crate::{ Dispatch, Runtime, UserEvent, WindowBuilder, }; -use http::{Request as HttpRequest, Response as HttpResponse}; use serde::{Deserialize, Deserializer}; use tauri_utils::{config::WindowConfig, Theme}; use url::Url; @@ -25,13 +24,13 @@ use std::{ use self::dpi::PhysicalPosition; -type UriSchemeProtocol = dyn Fn(HttpRequest>, Box>) + Send>) +type UriSchemeProtocol = dyn Fn(http::Request>, Box>) + Send>) + Send + Sync + 'static; type WebResourceRequestHandler = - dyn Fn(HttpRequest>, &mut HttpResponse>) + Send + Sync; + dyn Fn(http::Request>, &mut http::Response>) + Send + Sync; type NavigationHandler = dyn Fn(&Url) -> bool + Send; @@ -310,7 +309,7 @@ impl> PendingWindow { pub fn register_uri_scheme_protocol< N: Into, - H: Fn(HttpRequest>, Box>) + Send>) + H: Fn(http::Request>, Box>) + Send>) + Send + Sync + 'static, diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 26bc2d8ae91f..699dedbef1cb 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -8,7 +8,7 @@ use crate::{ channel::ChannelDataIpcQueue, CallbackFn, Invoke, InvokeError, InvokeHandler, InvokeResponder, InvokeResponse, }, - manager::{Asset, CustomProtocol, WindowManager}, + manager::{Asset, UriSchemeProtocol, WindowManager}, plugin::{Plugin, PluginStore}, runtime::{ webview::WebviewAttributes, @@ -32,7 +32,6 @@ use crate::menu::{Menu, MenuEvent}; use crate::tray::{TrayIcon, TrayIconBuilder, TrayIconEvent, TrayIconId}; #[cfg(desktop)] use crate::window::WindowMenu; -use http::{Request as HttpRequest, Response as HttpResponse}; use raw_window_handle::HasRawDisplayHandle; use serde::Deserialize; use serialize_to_javascript::{default_template, DefaultTemplate, Template}; @@ -991,7 +990,7 @@ pub struct Builder { plugins: PluginStore, /// The webview protocols available to all windows. - uri_scheme_protocols: HashMap>>, + uri_scheme_protocols: HashMap>>, /// App state. state: StateManager, @@ -1373,7 +1372,7 @@ impl Builder { pub fn register_uri_scheme_protocol< N: Into, T: Into>, - H: Fn(&AppHandle, HttpRequest>) -> HttpResponse + Send + Sync + 'static, + H: Fn(&AppHandle, http::Request>) -> http::Response + Send + Sync + 'static, >( mut self, uri_scheme: N, @@ -1381,7 +1380,7 @@ impl Builder { ) -> Self { self.uri_scheme_protocols.insert( uri_scheme.into(), - Arc::new(CustomProtocol { + Arc::new(UriSchemeProtocol { protocol: Box::new(move |app, request, responder| { responder.respond(protocol(app, request)) }), @@ -1421,7 +1420,7 @@ impl Builder { #[must_use] pub fn register_asynchronous_uri_scheme_protocol< N: Into, - H: Fn(&AppHandle, HttpRequest>, UriSchemeResponder) + Send + Sync + 'static, + H: Fn(&AppHandle, http::Request>, UriSchemeResponder) + Send + Sync + 'static, >( mut self, uri_scheme: N, @@ -1429,7 +1428,7 @@ impl Builder { ) -> Self { self.uri_scheme_protocols.insert( uri_scheme.into(), - Arc::new(CustomProtocol { + Arc::new(UriSchemeProtocol { protocol: Box::new(protocol), }), ); @@ -1645,14 +1644,14 @@ impl Builder { } } -pub(crate) type UriSchemeResponderFn = Box>) + Send>; +pub(crate) type UriSchemeResponderFn = Box>) + Send>; pub struct UriSchemeResponder(pub(crate) UriSchemeResponderFn); impl UriSchemeResponder { /// Resolves the request with the given response. - pub fn respond>>(self, response: HttpResponse) { + pub fn respond>>(self, response: http::Response) { let (parts, body) = response.into_parts(); - (self.0)(HttpResponse::from_parts(parts, body.into())) + (self.0)(http::Response::from_parts(parts, body.into())) } } diff --git a/core/tauri/src/ipc/protocol.rs b/core/tauri/src/ipc/protocol.rs index b6ad12602305..181e8c97d5c2 100644 --- a/core/tauri/src/ipc/protocol.rs +++ b/core/tauri/src/ipc/protocol.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; use http::{ header::{ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE}, - HeaderValue, Method, Request as HttpRequest, Response as HttpResponse, StatusCode, + HeaderValue, Method, StatusCode, }; use crate::{ @@ -49,15 +49,16 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro Box::new(move |_window, _cmd, response, _callback, _error| { let (mut response, mime_type) = match response { InvokeResponse::Ok(InvokeBody::Json(v)) => ( - HttpResponse::new(serde_json::to_vec(&v).unwrap().into()), + http::Response::new(serde_json::to_vec(&v).unwrap().into()), mime::APPLICATION_JSON, ), - InvokeResponse::Ok(InvokeBody::Raw(v)) => { - (HttpResponse::new(v.into()), mime::APPLICATION_OCTET_STREAM) - } + InvokeResponse::Ok(InvokeBody::Raw(v)) => ( + http::Response::new(v.into()), + mime::APPLICATION_OCTET_STREAM, + ), InvokeResponse::Err(e) => { let mut response = - HttpResponse::new(serde_json::to_vec(&e.0).unwrap().into()); + http::Response::new(serde_json::to_vec(&e.0).unwrap().into()); *response.status_mut() = StatusCode::BAD_REQUEST; (response, mime::TEXT_PLAIN) } @@ -74,7 +75,7 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro } Err(e) => { respond( - HttpResponse::builder() + http::Response::builder() .status(StatusCode::BAD_REQUEST) .header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str()) .body(e.as_bytes().to_vec().into()) @@ -84,7 +85,7 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro } } else { respond( - HttpResponse::builder() + http::Response::builder() .status(StatusCode::BAD_REQUEST) .header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str()) .body( @@ -99,7 +100,7 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro } Method::OPTIONS => { - let mut r = HttpResponse::new(Vec::new().into()); + let mut r = http::Response::new(Vec::new().into()); r.headers_mut().insert( ACCESS_CONTROL_ALLOW_HEADERS, HeaderValue::from_static("Content-Type, Tauri-Callback, Tauri-Error, Tauri-Channel-Id"), @@ -108,7 +109,7 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro } _ => { - let mut r = HttpResponse::new( + let mut r = http::Response::new( "only POST and OPTIONS are allowed" .as_bytes() .to_vec() @@ -286,7 +287,7 @@ fn handle_ipc_message(message: String, manager: &WindowManager, l fn parse_invoke_request( #[allow(unused_variables)] manager: &WindowManager, - request: HttpRequest>, + request: http::Request>, ) -> std::result::Result { #[allow(unused_mut)] let (parts, mut body) = request.into_parts(); diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 704ed0553293..105133870a0f 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -19,7 +19,6 @@ use serde::Serialize; use serialize_to_javascript::{default_template, DefaultTemplate, Template}; use url::Url; -use http::Request as HttpRequest; use tauri_macros::default_runtime; use tauri_utils::debug_eprintln; use tauri_utils::{ @@ -236,7 +235,7 @@ pub struct InnerWindowManager { package_info: PackageInfo, /// The webview protocols available to all windows. - uri_scheme_protocols: HashMap>>, + uri_scheme_protocols: HashMap>>, /// A set containing a reference to the active menus, including /// the app-wide menu and the window-specific menus /// @@ -305,10 +304,11 @@ pub struct Asset { } /// Uses a custom URI scheme handler to resolve file requests -pub struct CustomProtocol { +pub struct UriSchemeProtocol { /// Handler for protocol #[allow(clippy::type_complexity)] - pub protocol: Box, HttpRequest>, UriSchemeResponder) + Send + Sync>, + pub protocol: + Box, http::Request>, UriSchemeResponder) + Send + Sync>, } #[default_runtime(crate::Wry, wry)] @@ -332,7 +332,7 @@ impl WindowManager { plugins: PluginStore, invoke_handler: Box>, on_page_load: Box>, - uri_scheme_protocols: HashMap>>, + uri_scheme_protocols: HashMap>>, state: StateManager, window_event_listeners: Vec>, #[cfg(desktop)] window_menu_event_listeners: HashMap< diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 351ce0d0f317..791344ad5d62 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -43,7 +43,6 @@ use crate::{ CursorIcon, Icon, }; -use http::{Request as HttpRequest, Response as HttpResponse}; use serde::Serialize; #[cfg(windows)] use windows::Win32::Foundation::HWND; @@ -60,10 +59,10 @@ use std::{ }; pub(crate) type WebResourceRequestHandler = - dyn Fn(HttpRequest>, &mut HttpResponse>) + Send + Sync; + dyn Fn(http::Request>, &mut http::Response>) + Send + Sync; pub(crate) type NavigationHandler = dyn Fn(&Url) -> bool + Send; pub(crate) type UriSchemeProtocolHandler = - Box>, UriSchemeResponder) + Send + Sync>; + Box>, UriSchemeResponder) + Send + Sync>; #[derive(Clone, Serialize)] struct WindowCreatedEvent { @@ -292,7 +291,7 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> { /// }); /// ``` pub fn on_web_resource_request< - F: Fn(HttpRequest>, &mut HttpResponse>) + Send + Sync + 'static, + F: Fn(http::Request>, &mut http::Response>) + Send + Sync + 'static, >( mut self, f: F,