fixed incorrect response buffer reset in manual redirection handling in do_propfind_request

Thu, 15 Oct 2015 11:41:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Oct 2015 11:41:06 +0200
changeset 166
8911170d5e78
parent 165
b66bed169fc3
child 167
cecfbb5f8618

fixed incorrect response buffer reset in manual redirection handling in do_propfind_request

libidav/methods.c file | annotate | diff | comparison | revisions
--- a/libidav/methods.c	Thu Oct 15 11:05:27 2015 +0200
+++ b/libidav/methods.c	Thu Oct 15 11:41:06 2015 +0200
@@ -48,9 +48,11 @@
 {
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
     
+    // implement own redirection follower
     long follow = 0;
     curl_easy_getinfo(handle, CURLOPT_FOLLOWLOCATION, &follow);
-    int maxredirect = 16;
+    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
+    const int maxredirect = 16;
     
     struct curl_slist *headers = NULL;
     CURLcode ret = 0;
@@ -63,7 +65,6 @@
     curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
     curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
     
-    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
     for(int i=0;i<=maxredirect;i++) {
         char *url = NULL;
         curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
@@ -83,13 +84,15 @@
         }
         headers = curl_slist_append(headers, "Content-Type: text/xml");
         curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
-        
-        ucx_buffer_seek(request, 0, SEEK_SET);
-        ucx_buffer_seek(response, 0 , SEEK_SET);
+
+        // reset buffers and perform request
+        request->pos = 0;
+        response->size = response->pos = 0;
         ret = curl_easy_perform(handle);
         curl_slist_free_all(headers);
         headers = NULL;
         
+        // continue work with URL we get from the server!
         char *location = NULL;
         curl_easy_getinfo(handle, CURLINFO_REDIRECT_URL, &location);
         if(location) {

mercurial