# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1444816179 -7200
# Node ID 25374afa56162328cd843d4173dcc9295b233d57
# Parent  97a52ce52b1a457097f59e0c6b114033f4a0b6ee
using Depth: 0 for non collection resources

diff -r 97a52ce52b1a -r 25374afa5616 libidav/methods.c
--- a/libidav/methods.c	Tue Oct 13 16:10:58 2015 +0200
+++ b/libidav/methods.c	Wed Oct 14 11:49:39 2015 +0200
@@ -49,8 +49,26 @@
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
     
     struct curl_slist *headers = NULL;
+    
+    char *url = NULL;
+    curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
+    if(url) {
+        size_t ulen = strlen(url);
+        if(ulen > 0) {
+            if(url[ulen-1] == '/') {
+                headers = curl_slist_append(headers, "Depth: 1");
+            } else {
+                headers = curl_slist_append(headers, "Depth: 0");
+            }
+        } else {
+            return CURLE_URL_MALFORMAT;
+        }
+    } else {
+        return CURLE_URL_MALFORMAT;
+    }
+    
     headers = curl_slist_append(headers, "Content-Type: text/xml");
-    headers = curl_slist_append(headers, "Depth: 1");
+    
     curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
     
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);