From 468d74875bb3dd81659464b330f768386ab05900 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:49:33 +0200 Subject: [PATCH] A few fixes to MKCALENDAR --- .../caldav/src/calendar/methods/mkcalendar.rs | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/caldav/src/calendar/methods/mkcalendar.rs b/crates/caldav/src/calendar/methods/mkcalendar.rs index bfae5b3..305db73 100644 --- a/crates/caldav/src/calendar/methods/mkcalendar.rs +++ b/crates/caldav/src/calendar/methods/mkcalendar.rs @@ -25,14 +25,14 @@ pub struct CalendarComponentElement { #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "kebab-case")] pub struct SupportedCalendarComponentSetElement { - #[serde(flatten)] + #[serde(rename = "$value")] comp: Vec, } #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "kebab-case")] pub struct MkcolCalendarProp { - resourcetype: Resourcetype, + resourcetype: Option, displayname: Option, calendar_description: Option, calendar_color: Option, @@ -52,11 +52,6 @@ struct MkcalendarRequest { set: PropElement, } -// TODO: Not sure yet what to send back :) -#[derive(Serialize, Clone, Debug)] -#[serde(rename = "mkcalendar-response")] -struct MkcalendarResponse; - pub async fn route_mkcol_calendar( path: Path<(String, String)>, body: String, @@ -80,6 +75,20 @@ pub async fn route_mkcol_calendar { + // No conflict, no worries + } + Ok(_) => { + // oh no, there's a conflict + return Ok(HttpResponse::Conflict().body("A calendar already exists at this URI")); + } + Err(err) => { + // some other error + return Err(err.into()); + } + } + match context .store .write() @@ -87,10 +96,14 @@ pub async fn route_mkcol_calendar { - let response = quick_xml::se::to_string(&MkcalendarResponse).unwrap(); - Ok(HttpResponse::Created().body(response)) + // The spec says we should return a mkcalendar-response but I don't know what goes into it. + // However, it works without one but breaks on iPadOS when using an empty one :) + Ok(()) => Ok(HttpResponse::Created() + .insert_header(("Cache-Control", "no-cache")) + .body("")), + Err(err) => { + dbg!(err.to_string()); + Err(err.into()) } - Err(_err) => Ok(HttpResponse::InternalServerError().body("")), } }