浏览代码

Bug fix: S3 temporary redirect was not handled (consequently it was not possible to work with newly created S3 buckets) + Bug fix: HTTP error was displaying instead of a more specific S3 error message in some situations

Source commit: b27713bb4e170c22482afa81ba9a51046836ed18
Martin Prikryl 7 年之前
父节点
当前提交
6b25e81f73
共有 2 个文件被更改,包括 21 次插入10 次删除
  1. 1 1
      libs/libs3/inc/request.h
  2. 20 9
      libs/libs3/src/request.c

+ 1 - 1
libs/libs3/inc/request.h

@@ -185,7 +185,7 @@ void request_perform(const RequestParams *params, S3RequestContext *context);
 
 // Called by the internal request code or internal request context code when a
 // curl has finished the request
-void request_finish(Request *request);
+void request_finish(Request *request, NeonCode code); // WINSCP (code)
 
 S3Status request_neon_code_to_status(NeonCode code); // WINSCP (neon)
 

+ 20 - 9
libs/libs3/src/request.c

@@ -1574,22 +1574,15 @@ void request_perform(const RequestParams *params, S3RequestContext *context)
     #endif
     {
         NeonCode code = ne_request_dispatch(request->NeonRequest);
-        if ((code != NE_OK) && (request->status == S3StatusOK)) {
-            request->status = request_neon_code_to_status(code);
-            const char * neonError = ne_get_error(request->NeonSession);
-            int allFit;
-            string_buffer_append(request->statusMessage, neonError, strlen(neonError), allFit);
-            request->errorParser.s3ErrorDetails.message = request->statusMessage;
-        }
 
         // Finish the request, ensuring that all callbacks have been made, and
         // also releases the request
-        request_finish(request);
+        request_finish(request, code);
     }
 }
 
 
-void request_finish(Request *request)
+void request_finish(Request *request, NeonCode code)
 {
     // If we haven't detected this already, we now know that the headers are
     // definitely done being read in
@@ -1597,12 +1590,30 @@ void request_finish(Request *request)
 
     // If there was no error processing the request, then possibly there was
     // an S3 error parsed, which should be converted into the request status
+    // WINSCP: We get "OK", even if there's TCP or HTTP error
     if (request->status == S3StatusOK) {
+        // First handle S3 errors
+        // TemporaryRedirect S3 error has a precedence over HTTP 3xx error that carries it.
         error_parser_convert_status(&(request->errorParser),
                                     &(request->status));
+        #ifdef WINSCP
+        // This handles TCP and HTTP errors
+        if (request->status == S3StatusOK) {
+            if (code != NE_OK) {
+                request->status = request_neon_code_to_status(code);
+                if (request->errorParser.s3ErrorDetails.message == NULL) {
+                    const char * neonError = ne_get_error(request->NeonSession);
+                    int allFit;
+                    string_buffer_append(request->statusMessage, neonError, strlen(neonError), allFit);
+                    request->errorParser.s3ErrorDetails.message = request->statusMessage;
+                }
+            }
+        }
+        #endif
         // If there still was no error recorded, then it is possible that
         // there was in fact an error but that there was no error XML
         // detailing the error
+        // WINSCP: We possibly never get here with neon
         if ((request->status == S3StatusOK) &&
             ((request->httpResponseCode < 200) ||
              (request->httpResponseCode > 299))) {