use reqwest::{header::CONTENT_TYPE, Response};
use crate::ALL_DROP;
pub struct WebDAVClient {
inner: reqwest::Client,
webdav_url: String,
username: String,
password: String,
}
impl WebDAVClient {
pub fn new(webdav: &str, username: &str, password: &str) -> Self {
Self {
inner: reqwest::Client::new(),
webdav_url: webdav.to_owned(),
username: username.to_owned(),
password: password.to_owned(),
}
}
pub async fn get(&self, url: &str) -> reqwest::Result<Response> {
let url = if self.webdav_url.is_empty() {
url.to_owned()
} else {
format!("{}/{}", self.webdav_url, url)
};
self.inner
.get(url)
.basic_auth(&self.username, Some(&self.password))
.send()
.await
}
pub async fn all_propfind(&self, url: &str) -> reqwest::Result<Response> {
let url = if self.webdav_url.is_empty() {
url.to_owned()
} else {
format!("{}/{}", self.webdav_url, url)
};
self.inner
.request(reqwest::Method::from_bytes(b"PROPFIND").unwrap(), url)
.basic_auth(&self.username, Some(&self.password))
.header(CONTENT_TYPE, "application/xml")
.body(ALL_DROP)
.send()
.await
}
}