]> OzVa Git service - ozva-cloud/commitdiff
feat: add webdav proppatch handler (#18)
authorsigoden <sigoden@gmail.com>
Sat, 4 Jun 2022 23:35:05 +0000 (07:35 +0800)
committerGitHub <noreply@github.com>
Sat, 4 Jun 2022 23:35:05 +0000 (07:35 +0800)
src/server.rs

index 5c8a8e6b3df48e0eaea2c03d99ad589e8d76e85a..983a8d5b4a40d417e7c6e8c66843d76aee64d9cd 100644 (file)
@@ -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#"<?xml version="1.0" encoding="utf-8"?>
 <D:prop xmlns:D="DAV:"><D:lockdiscovery><D:activelock>
-       <D:locktoken><D:href>{}</D:href></D:locktoken>
-       <D:lockroot><D:href>{}</D:href></D:lockroot>
+<D:locktoken><D:href>{}</D:href></D:locktoken>
+<D:lockroot><D:href>{}</D:href></D:lockroot>
 </D:activelock></D:lockdiscovery></D:prop>"#,
             token, req_path
         ));
         Ok(())
     }
 
+    async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> {
+        let output = format!(
+            r#"<D:response>
+<D:href>{}</D:href>
+<D:propstat>
+<D:prop>
+</D:prop>
+<D:status>HTTP/1.1 403 Forbidden</D:status>
+</D:propstat>
+</D:response>"#,
+            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",