From 5578ee91903c7624a3f390e35c754cfa47b06fae Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Jun 2022 07:35:05 +0800 Subject: [PATCH] feat: add webdav proppatch handler (#18) --- src/server.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/server.rs b/src/server.rs index 5c8a8e6..983a8d5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -251,7 +251,7 @@ impl InnerService { } "PROPPATCH" => { if is_file { - self.handle_propfind_file(path, &mut res).await?; + self.handle_proppatch(req_path, &mut res).await?; } else { status!(res, StatusCode::NOT_FOUND); } @@ -533,13 +533,13 @@ impl InnerService { acc.push_str(&v); acc }); - res_propfind(res, &output); + res_multistatus(res, &output); Ok(()) } async fn handle_propfind_file(&self, path: &Path, res: &mut Response) -> BoxResult<()> { if let Some(pathitem) = self.to_pathitem(path, &self.args.path).await? { - res_propfind(res, &pathitem.to_dav_xml(self.args.uri_prefix.as_str())); + res_multistatus(res, &pathitem.to_dav_xml(self.args.uri_prefix.as_str())); } else { status!(res, StatusCode::NOT_FOUND); } @@ -619,14 +619,30 @@ impl InnerService { *res.body_mut() = Body::from(format!( r#" - {} - {} +{} +{} "#, token, req_path )); Ok(()) } + async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> { + let output = format!( + r#" +{} + + + +HTTP/1.1 403 Forbidden + +"#, + req_path + ); + res_multistatus(res, &output); + Ok(()) + } + fn send_index( &self, path: &Path, @@ -882,7 +898,7 @@ fn add_cors(res: &mut Response) { ); } -fn res_propfind(res: &mut Response, content: &str) { +fn res_multistatus(res: &mut Response, content: &str) { *res.status_mut() = StatusCode::MULTI_STATUS; res.headers_mut().insert( "content-type",