tauri_updater/
http.rs

1use attohttpc;
2use serde::Serialize;
3
4use std::io::{BufWriter, Write};
5
6pub(crate) mod link_value;
7
8pub fn get(url: String) -> crate::Result<attohttpc::Response> {
9  let response = attohttpc::get(url).send()?;
10
11  Ok(response)
12}
13
14pub fn post_as_json<T: Serialize>(url: String, payload: &T) -> crate::Result<attohttpc::Response> {
15  let response = attohttpc::post(url).json(payload)?.send()?;
16
17  Ok(response)
18}
19
20pub fn download<T: Write>(url: String, dest: T, _display_progress: bool) -> crate::Result<()> {
21  set_ssl_vars!();
22
23  let resp = get(url)?;
24
25  if !resp.status().is_success() {
26    bail!(
27      crate::ErrorKind::Download,
28      "Download request failed with status: {:?}",
29      resp.status()
30    )
31  }
32
33  let file = BufWriter::new(dest);
34  resp.write_to(file)?;
35  Ok(())
36}