Added utils::build_url

This commit is contained in:
daladim 2021-03-21 23:34:37 +01:00
parent a8ccdef0bb
commit 50ac358791
2 changed files with 12 additions and 6 deletions

View file

@ -115,8 +115,7 @@ impl Client {
} }
let href = self.sub_request_and_process(&self.url, DAVCLIENT_BODY.into(), &["current-user-principal", "href"]).await?; let href = self.sub_request_and_process(&self.url, DAVCLIENT_BODY.into(), &["current-user-principal", "href"]).await?;
let mut principal_url = self.url.clone(); let principal_url = crate::utils::build_url(&self.url, &href);
principal_url.set_path(&href);
self.cached_replies.lock().unwrap().principal = Some(principal_url.clone()); self.cached_replies.lock().unwrap().principal = Some(principal_url.clone());
log::debug!("Principal URL is {}", href); log::debug!("Principal URL is {}", href);
@ -131,8 +130,7 @@ impl Client {
let principal_url = self.get_principal().await?; let principal_url = self.get_principal().await?;
let href = self.sub_request_and_process(&principal_url, HOMESET_BODY.into(), &["calendar-home-set", "href"]).await?; let href = self.sub_request_and_process(&principal_url, HOMESET_BODY.into(), &["calendar-home-set", "href"]).await?;
let mut chs_url = self.url.clone(); let chs_url = crate::utils::build_url(&self.url, &href);
chs_url.set_path(&href);
self.cached_replies.lock().unwrap().calendar_home_set = Some(chs_url.clone()); self.cached_replies.lock().unwrap().calendar_home_set = Some(chs_url.clone());
log::debug!("Calendar home set URL is {:?}", chs_url.path()); log::debug!("Calendar home set URL is {:?}", chs_url.path());
@ -184,8 +182,7 @@ impl Client {
Some(h) => h.text(), Some(h) => h.text(),
}; };
let mut this_calendar_url = self.url.clone(); let this_calendar_url = crate::utils::build_url(&self.url, &calendar_href);
this_calendar_url.set_path(&calendar_href);
let supported_components = match crate::calendar::SupportedComponents::try_from(el_supported_comps.clone()) { let supported_components = match crate::calendar::SupportedComponents::try_from(el_supported_comps.clone()) {
Err(err) => { Err(err) => {

View file

@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use minidom::Element; use minidom::Element;
use url::Url;
use crate::traits::CompleteCalendar; use crate::traits::CompleteCalendar;
use crate::calendar::CalendarId; use crate::calendar::CalendarId;
@ -45,6 +46,14 @@ pub fn find_elem<S: AsRef<str>>(root: &Element, searched_name: S) -> Option<&Ele
None None
} }
/// Build a new Url by keeping the same scheme and server from `base` but changing the path part
pub fn build_url(base: &Url, new_path: &str) -> Url {
let mut built = base.clone();
built.set_path(&new_path);
built
}
pub fn print_xml(element: &Element) { pub fn print_xml(element: &Element) {
use std::io::Write; use std::io::Write;
let mut writer = std::io::stdout(); let mut writer = std::io::stdout();