Browse Source

docs: use `http::*` qualified import instead of an alias (#7873)

Amr Bashir 1 year ago
parent
commit
c3ac1f836b

+ 3 - 4
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<Vec<u8>>, Box<dyn FnOnce(HttpResponse<Cow<'static, [u8]>>) + Send>)
+type UriSchemeProtocol = dyn Fn(http::Request<Vec<u8>>, Box<dyn FnOnce(http::Response<Cow<'static, [u8]>>) + Send>)
   + Send
   + Sync
   + 'static;
 
 type WebResourceRequestHandler =
-  dyn Fn(HttpRequest<Vec<u8>>, &mut HttpResponse<Cow<'static, [u8]>>) + Send + Sync;
+  dyn Fn(http::Request<Vec<u8>>, &mut http::Response<Cow<'static, [u8]>>) + Send + Sync;
 
 type NavigationHandler = dyn Fn(&Url) -> bool + Send;
 
@@ -310,7 +309,7 @@ impl<T: UserEvent, R: Runtime<T>> PendingWindow<T, R> {
 
   pub fn register_uri_scheme_protocol<
     N: Into<String>,
-    H: Fn(HttpRequest<Vec<u8>>, Box<dyn FnOnce(HttpResponse<Cow<'static, [u8]>>) + Send>)
+    H: Fn(http::Request<Vec<u8>>, Box<dyn FnOnce(http::Response<Cow<'static, [u8]>>) + Send>)
       + Send
       + Sync
       + 'static,

+ 9 - 10
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<R: Runtime> {
   plugins: PluginStore<R>,
 
   /// The webview protocols available to all windows.
-  uri_scheme_protocols: HashMap<String, Arc<CustomProtocol<R>>>,
+  uri_scheme_protocols: HashMap<String, Arc<UriSchemeProtocol<R>>>,
 
   /// App state.
   state: StateManager,
@@ -1373,7 +1372,7 @@ impl<R: Runtime> Builder<R> {
   pub fn register_uri_scheme_protocol<
     N: Into<String>,
     T: Into<Cow<'static, [u8]>>,
-    H: Fn(&AppHandle<R>, HttpRequest<Vec<u8>>) -> HttpResponse<T> + Send + Sync + 'static,
+    H: Fn(&AppHandle<R>, http::Request<Vec<u8>>) -> http::Response<T> + Send + Sync + 'static,
   >(
     mut self,
     uri_scheme: N,
@@ -1381,7 +1380,7 @@ impl<R: Runtime> Builder<R> {
   ) -> 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<R: Runtime> Builder<R> {
   #[must_use]
   pub fn register_asynchronous_uri_scheme_protocol<
     N: Into<String>,
-    H: Fn(&AppHandle<R>, HttpRequest<Vec<u8>>, UriSchemeResponder) + Send + Sync + 'static,
+    H: Fn(&AppHandle<R>, http::Request<Vec<u8>>, UriSchemeResponder) + Send + Sync + 'static,
   >(
     mut self,
     uri_scheme: N,
@@ -1429,7 +1428,7 @@ impl<R: Runtime> Builder<R> {
   ) -> Self {
     self.uri_scheme_protocols.insert(
       uri_scheme.into(),
-      Arc::new(CustomProtocol {
+      Arc::new(UriSchemeProtocol {
         protocol: Box::new(protocol),
       }),
     );
@@ -1645,14 +1644,14 @@ impl<R: Runtime> Builder<R> {
   }
 }
 
-pub(crate) type UriSchemeResponderFn = Box<dyn FnOnce(HttpResponse<Cow<'static, [u8]>>) + Send>;
+pub(crate) type UriSchemeResponderFn = Box<dyn FnOnce(http::Response<Cow<'static, [u8]>>) + Send>;
 pub struct UriSchemeResponder(pub(crate) UriSchemeResponderFn);
 
 impl UriSchemeResponder {
   /// Resolves the request with the given response.
-  pub fn respond<T: Into<Cow<'static, [u8]>>>(self, response: HttpResponse<T>) {
+  pub fn respond<T: Into<Cow<'static, [u8]>>>(self, response: http::Response<T>) {
     let (parts, body) = response.into_parts();
-    (self.0)(HttpResponse::from_parts(parts, body.into()))
+    (self.0)(http::Response::from_parts(parts, body.into()))
   }
 }
 

+ 12 - 11
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<R: Runtime>(manager: WindowManager<R>, 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<R: Runtime>(manager: WindowManager<R>, 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<R: Runtime>(manager: WindowManager<R>, 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<R: Runtime>(manager: WindowManager<R>, 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<R: Runtime>(manager: WindowManager<R>, 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<R: Runtime>(message: String, manager: &WindowManager<R>, l
 
 fn parse_invoke_request<R: Runtime>(
   #[allow(unused_variables)] manager: &WindowManager<R>,
-  request: HttpRequest<Vec<u8>>,
+  request: http::Request<Vec<u8>>,
 ) -> std::result::Result<InvokeRequest, String> {
   #[allow(unused_mut)]
   let (parts, mut body) = request.into_parts();

+ 5 - 5
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<R: Runtime> {
 
   package_info: PackageInfo,
   /// The webview protocols available to all windows.
-  uri_scheme_protocols: HashMap<String, Arc<CustomProtocol<R>>>,
+  uri_scheme_protocols: HashMap<String, Arc<UriSchemeProtocol<R>>>,
   /// 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<R: Runtime> {
+pub struct UriSchemeProtocol<R: Runtime> {
   /// Handler for protocol
   #[allow(clippy::type_complexity)]
-  pub protocol: Box<dyn Fn(&AppHandle<R>, HttpRequest<Vec<u8>>, UriSchemeResponder) + Send + Sync>,
+  pub protocol:
+    Box<dyn Fn(&AppHandle<R>, http::Request<Vec<u8>>, UriSchemeResponder) + Send + Sync>,
 }
 
 #[default_runtime(crate::Wry, wry)]
@@ -332,7 +332,7 @@ impl<R: Runtime> WindowManager<R> {
     plugins: PluginStore<R>,
     invoke_handler: Box<InvokeHandler<R>>,
     on_page_load: Box<OnPageLoad<R>>,
-    uri_scheme_protocols: HashMap<String, Arc<CustomProtocol<R>>>,
+    uri_scheme_protocols: HashMap<String, Arc<UriSchemeProtocol<R>>>,
     state: StateManager,
     window_event_listeners: Vec<GlobalWindowEventListener<R>>,
     #[cfg(desktop)] window_menu_event_listeners: HashMap<

+ 3 - 4
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<Vec<u8>>, &mut HttpResponse<Cow<'static, [u8]>>) + Send + Sync;
+  dyn Fn(http::Request<Vec<u8>>, &mut http::Response<Cow<'static, [u8]>>) + Send + Sync;
 pub(crate) type NavigationHandler = dyn Fn(&Url) -> bool + Send;
 pub(crate) type UriSchemeProtocolHandler =
-  Box<dyn Fn(HttpRequest<Vec<u8>>, UriSchemeResponder) + Send + Sync>;
+  Box<dyn Fn(http::Request<Vec<u8>>, 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<Vec<u8>>, &mut HttpResponse<Cow<'static, [u8]>>) + Send + Sync + 'static,
+    F: Fn(http::Request<Vec<u8>>, &mut http::Response<Cow<'static, [u8]>>) + Send + Sync + 'static,
   >(
     mut self,
     f: F,