Skip to content

Commit 97f32d9

Browse files
committed
change cb signature
1 parent 6e37446 commit 97f32d9

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

plugins/websocket/src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use futures_util::{SinkExt, StreamExt, stream::SplitSink};
1313
use http::{
14-
Request,
14+
HeaderMap,
1515
header::{HeaderName, HeaderValue},
1616
};
1717
use serde::{Deserialize, Serialize, ser::Serializer};
@@ -150,7 +150,7 @@ async fn connect<R: Runtime>(
150150
config: Option<ConnectionConfig>,
151151
) -> Result<Id> {
152152
let id = rand::random();
153-
let mut request = url.into_client_request()?;
153+
let mut request = url.as_str().into_client_request()?;
154154

155155
if let Some(headers) = config.as_ref().and_then(|c| c.headers.as_ref()) {
156156
for (k, v) in headers {
@@ -161,7 +161,7 @@ async fn connect<R: Runtime>(
161161
}
162162

163163
if let Some(state) = window.app_handle().try_state::<RequestCallback<R>>() {
164-
(state.inner().0)(&mut request, window.app_handle());
164+
(state.inner().0)(url, request.headers_mut(), window.app_handle());
165165
}
166166

167167
#[cfg(any(feature = "rustls-tls", feature = "native-tls"))]
@@ -252,10 +252,11 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
252252
Builder::new().build()
253253
}
254254

255+
type RqCb<R> =
256+
Box<dyn Fn(String, &mut HeaderMap<HeaderValue>, &AppHandle<R>) + Send + Sync + 'static>;
257+
255258
/// Struct to provide concrete type for the manager
256-
struct RequestCallback<R: Runtime>(
257-
Box<dyn Fn(&mut Request<()>, &AppHandle<R>) + Send + Sync + 'static>,
258-
);
259+
struct RequestCallback<R: Runtime>(RqCb<R>);
259260

260261
pub struct Builder<R: Runtime> {
261262
tls_connector: Option<Connector>,
@@ -276,10 +277,7 @@ where
276277
/// add a callback which is able to modify the initial headers of the http upgrade request.
277278
/// This is useful for scenarios where the frontend may not know all the required headers that must be sent.
278279
/// e.g. in the scenario of http-only cookies
279-
pub fn merge_header_callback(
280-
mut self,
281-
cb: Box<dyn Fn(&mut Request<()>, &AppHandle<R>) + Send + Sync + 'static>,
282-
) -> Self {
280+
pub fn merge_header_callback(mut self, cb: RqCb<R>) -> Self {
283281
self.merge_headers.replace(RequestCallback(cb));
284282
self
285283
}

0 commit comments

Comments
 (0)