Skip to content

Commit

Permalink
remove own http types
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Sep 5, 2023
1 parent b6e5f8e commit e01901d
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 587 deletions.
5 changes: 5 additions & 0 deletions .changes/http-drop-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

No longer re-export the `http` crate.
7 changes: 7 additions & 0 deletions .changes/http-types-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:breaking
"tauri-runtime": patch:breaking
"tauri-runtime-wry": patch:breaking
---

`tauri-runtime` no longer implements its own HTTP types and relies on the `http` crate instead.
1 change: 1 addition & 0 deletions core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
rand = "0.8"
raw-window-handle = "0.5"
http = "0.2"

[target."cfg(windows)".dependencies]
webview2-com = "0.25"
Expand Down
47 changes: 3 additions & 44 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
use tauri_runtime::{
http::{header::CONTENT_TYPE, Request as HttpRequest, RequestParts, Response as HttpResponse},
monitor::Monitor,
webview::{WebviewIpcHandler, WindowBuilder, WindowBuilderBase},
window::{
Expand Down Expand Up @@ -61,7 +60,6 @@ use wry::{
UserAttentionType as WryUserAttentionType,
},
},
http::{Request as WryRequest, Response as WryResponse},
webview::{FileDropEvent as WryFileDropEvent, Url, WebContext, WebView, WebViewBuilder},
};

Expand All @@ -85,7 +83,6 @@ pub use wry::application::platform::macos::{
};

use std::{
borrow::Cow,
cell::RefCell,
collections::{
hash_map::Entry::{Occupied, Vacant},
Expand Down Expand Up @@ -259,40 +256,6 @@ impl<T: UserEvent> fmt::Debug for Context<T> {
}
}

struct HttpRequestWrapper(HttpRequest);

impl From<WryRequest<Vec<u8>>> for HttpRequestWrapper {
fn from(req: WryRequest<Vec<u8>>) -> Self {
let (parts, body) = req.into_parts();
let parts = RequestParts {
uri: parts.uri.to_string(),
method: parts.method,
headers: parts.headers,
};
Self(HttpRequest::new_internal(parts, body))
}
}

// response
struct HttpResponseWrapper(WryResponse<Cow<'static, [u8]>>);
impl From<HttpResponse> for HttpResponseWrapper {
fn from(response: HttpResponse) -> Self {
let (parts, body) = response.into_parts();
let mut res_builder = WryResponse::builder()
.status(parts.status)
.version(parts.version);
if let Some(mime) = parts.mimetype {
res_builder = res_builder.header(CONTENT_TYPE, mime);
}
for (name, val) in parts.headers.iter() {
res_builder = res_builder.header(name, val);
}

let res = res_builder.body(body).unwrap();
Self(res)
}
}

pub struct DeviceEventFilterWrapper(pub WryDeviceEventFilter);

impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
Expand Down Expand Up @@ -2702,14 +2665,10 @@ fn create_webview<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
}

for (scheme, protocol) in uri_scheme_protocols {
webview_builder =
webview_builder.with_custom_protocol(scheme, move |wry_request: WryRequest<Vec<u8>>, api| {
protocol(
HttpRequestWrapper::from(wry_request).0,
Box::new(move |response| api.respond(HttpResponseWrapper::from(response).0)),
)
webview_builder = webview_builder.with_custom_protocol(scheme, move |request, api| {
protocol(request, Box::new(move |response| api.respond(response)))
.map_err(|_| wry::Error::InitScriptError)
});
});
}

for script in webview_attributes.initialization_scripts {
Expand Down
1 change: 0 additions & 1 deletion core/tauri-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ thiserror = "1.0"
tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
http = "0.2.4"
http-range = "0.1.4"
raw-window-handle = "0.5"
rand = "0.8"
url = { version = "2" }
Expand Down
20 changes: 0 additions & 20 deletions core/tauri-runtime/src/http/mod.rs

This file was deleted.

132 changes: 0 additions & 132 deletions core/tauri-runtime/src/http/request.rs

This file was deleted.

Loading

0 comments on commit e01901d

Please sign in to comment.