[Curl] Fix timing of reporting error to the client
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 22:21:22 +0000 (22:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2018 22:21:22 +0000 (22:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184707

Before checking the result code, check the status of callback invocation and
do the right thing.

Patch by Basuke Suzuki <Basuke.Suzuki@sony.com> on 2018-04-17
Reviewed by Youenn Fablet.

No new tests because there's no new behavior.

* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::didCompleteTransfer):
* platform/network/curl/CurlRequest.h:
(WebCore::CurlRequest::needToInvokeDidReceiveResponse const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230734 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/curl/CurlRequest.cpp
Source/WebCore/platform/network/curl/CurlRequest.h

index 71f1578..e56732a 100644 (file)
@@ -1,5 +1,22 @@
 2018-04-17  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
+        [Curl] Fix timing of reporting error to the client
+        https://bugs.webkit.org/show_bug.cgi?id=184707
+
+        Before checking the result code, check the status of callback invocation and
+        do the right thing.
+
+        Reviewed by Youenn Fablet.
+
+        No new tests because there's no new behavior.
+
+        * platform/network/curl/CurlRequest.cpp:
+        (WebCore::CurlRequest::didCompleteTransfer):
+        * platform/network/curl/CurlRequest.h:
+        (WebCore::CurlRequest::needToInvokeDidReceiveResponse const):
+
+2018-04-17  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
         [Curl] Export authentication information to be used by the client.
         https://bugs.webkit.org/show_bug.cgi?id=184709
 
index c90ebd0..47dd6f4 100644 (file)
@@ -410,25 +410,26 @@ void CurlRequest::didCompleteTransfer(CURLcode result)
         return;
     }
 
+    if (needToInvokeDidReceiveResponse()) {
+        // Processing of didReceiveResponse() has not been completed. (For example, HEAD method)
+        // When completeDidReceiveResponse() is called, didCompleteTransfer() will be called again.
+
+        m_finishedResultCode = result;
+        invokeDidReceiveResponse(m_response, Action::FinishTransfer);
+        return;
+    }
+
     if (result == CURLE_OK) {
-        if (needToInvokeDidReceiveResponse()) {
-            // Processing of didReceiveResponse() has not been completed. (For example, HEAD method)
-            // When completeDidReceiveResponse() is called, didCompleteTransfer() will be called again.
-
-            m_finishedResultCode = result;
-            invokeDidReceiveResponse(m_response, Action::FinishTransfer);
-        } else {
-            if (m_multipartHandle)
-                m_multipartHandle->didComplete();
-
-            if (auto metrics = m_curlHandle->getNetworkLoadMetrics())
-                m_networkLoadMetrics = *metrics;
-
-            finalizeTransfer();
-            callClient([](CurlRequest& request, CurlRequestClient& client) {
-                client.curlDidComplete(request);
-            });
-        }
+        if (m_multipartHandle)
+            m_multipartHandle->didComplete();
+
+        if (auto metrics = m_curlHandle->getNetworkLoadMetrics())
+            m_networkLoadMetrics = *metrics;
+
+        finalizeTransfer();
+        callClient([](CurlRequest& request, CurlRequestClient& client) {
+            client.curlDidComplete(request);
+        });
     } else {
         auto type = (result == CURLE_OPERATION_TIMEDOUT && m_request.timeoutInterval() > 0.0) ? ResourceError::Type::Timeout : ResourceError::Type::General;
         auto resourceError = ResourceError::httpError(result, m_request.url(), type);
index f884ce1..92c451e 100644 (file)
@@ -127,7 +127,7 @@ private:
     void setupSendData(bool forPutMethod);
 
     // Processing for DidReceiveResponse
-    bool needToInvokeDidReceiveResponse() const { return !m_didNotifyResponse || !m_didReturnFromNotify; }
+    bool needToInvokeDidReceiveResponse() const { return m_didReceiveResponse && (!m_didNotifyResponse || !m_didReturnFromNotify); }
     bool needToInvokeDidCancelTransfer() const { return m_didNotifyResponse && !m_didReturnFromNotify && m_actionAfterInvoke == Action::FinishTransfer; }
     void invokeDidReceiveResponseForFile(URL&);
     void invokeDidReceiveResponse(const CurlResponse&, Action);