Skip to content

Commit 5c85af7

Browse files
committed
remove unsafe code
1 parent d26da61 commit 5c85af7

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

plugins/http/src/commands.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222

2323
const HTTP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
2424

25-
struct ReqwestResponse(reqwest::Response);
25+
struct ReqwestResponse(Mutex<reqwest::Response>);
2626
impl tauri::Resource for ReqwestResponse {}
2727

2828
type CancelableResponseResult = Result<reqwest::Response>;
@@ -403,7 +403,7 @@ pub async fn fetch_send<R: Runtime>(
403403
}
404404

405405
let mut resources_table = webview.resources_table();
406-
let rid = resources_table.add(ReqwestResponse(res));
406+
let rid = resources_table.add(ReqwestResponse(Mutex::new(res)));
407407

408408
Ok(FetchResponse {
409409
status: status.as_u16(),
@@ -424,13 +424,7 @@ pub async fn fetch_read_body<R: Runtime>(
424424
resources_table.get::<ReqwestResponse>(rid)?
425425
};
426426

427-
// SAFETY: we can access the inner value mutably
428-
// because we are the only ones with a reference to it
429-
// and we don't want to use `Arc::into_inner` because we want to keep the value in the table
430-
// for potential future calls to `fetch_cancel_body`
431-
let res_ptr = Arc::as_ptr(&res) as *mut ReqwestResponse;
432-
let res = unsafe { &mut *res_ptr };
433-
let res = &mut res.0;
427+
let mut res = res.0.lock().await;
434428

435429
let Some(chunk) = res.chunk().await? else {
436430
let mut resources_table = webview.resources_table();

0 commit comments

Comments
 (0)