Title: [229347] trunk/Source/WebCore
Revision
229347
Author
commit-qu...@webkit.org
Date
2018-03-06 16:32:20 -0800 (Tue, 06 Mar 2018)

Log Message

[Curl] Remove unnecessary copied ResourceRequest member variable.
https://bugs.webkit.org/show_bug.cgi?id=183010

Patch by Basuke Suzuki <basuke.suz...@sony.com> on 2018-03-06
Reviewed by Youenn Fablet.

* platform/network/ResourceHandle.h:
* platform/network/ResourceHandleInternal.h:
(WebCore::ResourceHandleInternal::ResourceHandleInternal):
* platform/network/curl/CurlRequest.h:
(WebCore::CurlRequest::resourceRequest const):
* platform/network/curl/ResourceHandleCurl.cpp:
(WebCore::ResourceHandle::start):
(WebCore::ResourceHandle::addCacheValidationHeaders):
(WebCore::ResourceHandle::createCurlRequest):
(WebCore::ResourceHandle::restartRequestWithCredential):
(WebCore::ResourceHandle::continueAfterWillSendRequest):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229346 => 229347)


--- trunk/Source/WebCore/ChangeLog	2018-03-06 23:26:21 UTC (rev 229346)
+++ trunk/Source/WebCore/ChangeLog	2018-03-07 00:32:20 UTC (rev 229347)
@@ -1,3 +1,22 @@
+2018-03-06  Basuke Suzuki  <basuke.suz...@sony.com>
+
+        [Curl] Remove unnecessary copied ResourceRequest member variable.
+        https://bugs.webkit.org/show_bug.cgi?id=183010
+
+        Reviewed by Youenn Fablet.
+
+        * platform/network/ResourceHandle.h:
+        * platform/network/ResourceHandleInternal.h:
+        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
+        * platform/network/curl/CurlRequest.h:
+        (WebCore::CurlRequest::resourceRequest const):
+        * platform/network/curl/ResourceHandleCurl.cpp:
+        (WebCore::ResourceHandle::start):
+        (WebCore::ResourceHandle::addCacheValidationHeaders):
+        (WebCore::ResourceHandle::createCurlRequest):
+        (WebCore::ResourceHandle::restartRequestWithCredential):
+        (WebCore::ResourceHandle::continueAfterWillSendRequest):
+
 2018-03-06  Nan Wang  <n_w...@apple.com>
 
         AX: Flaky test after r229310

Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (229346 => 229347)


--- trunk/Source/WebCore/platform/network/ResourceHandle.h	2018-03-06 23:26:21 UTC (rev 229346)
+++ trunk/Source/WebCore/platform/network/ResourceHandle.h	2018-03-07 00:32:20 UTC (rev 229347)
@@ -297,8 +297,14 @@
 #endif
 
 #if USE(CURL)
-    Ref<CurlRequest> createCurlRequest(ResourceRequest&);
+    enum class RequestStatus {
+        NewRequest,
+        ReusedRequest
+    };
 
+    void addCacheValidationHeaders(ResourceRequest&);
+    Ref<CurlRequest> createCurlRequest(ResourceRequest&, RequestStatus = RequestStatus::NewRequest);
+
     bool shouldRedirectAsGET(const ResourceRequest&, bool crossOrigin);
 
     std::optional<std::pair<String, String>> getCredential(ResourceRequest&, bool);

Modified: trunk/Source/WebCore/platform/network/ResourceHandleInternal.h (229346 => 229347)


--- trunk/Source/WebCore/platform/network/ResourceHandleInternal.h	2018-03-06 23:26:21 UTC (rev 229346)
+++ trunk/Source/WebCore/platform/network/ResourceHandleInternal.h	2018-03-07 00:32:20 UTC (rev 229347)
@@ -76,7 +76,7 @@
         , m_defersLoading(defersLoading)
         , m_shouldContentSniff(shouldContentSniff)
         , m_shouldContentEncodingSniff(shouldContentEncodingSniff)
-#if USE(CFURLCONNECTION) || USE(CURL)
+#if USE(CFURLCONNECTION)
         , m_currentRequest(request)
 #endif
 #if USE(SOUP)
@@ -129,7 +129,6 @@
 #if USE(CURL)
     std::unique_ptr<CurlResourceHandleDelegate> m_delegate;
     
-    ResourceRequest m_currentRequest;
     bool m_cancelled { false };
     unsigned m_redirectCount { 0 };
     unsigned m_authFailureCount { 0 };

Modified: trunk/Source/WebCore/platform/network/curl/CurlRequest.h (229346 => 229347)


--- trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2018-03-06 23:26:21 UTC (rev 229346)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2018-03-07 00:32:20 UTC (rev 229347)
@@ -71,6 +71,7 @@
     void suspend();
     void resume();
 
+    const ResourceRequest& resourceRequest() const { return m_request; }
     bool isSyncRequest() const { return m_isSyncRequest; }
     bool isCompleted() const { return !m_curlHandle; }
     bool isCancelled() const { return m_cancelled; }

Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp (229346 => 229347)


--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp	2018-03-06 23:26:21 UTC (rev 229346)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp	2018-03-07 00:32:20 UTC (rev 229347)
@@ -83,9 +83,9 @@
         return true;
     }
 
-    d->m_curlRequest = createCurlRequest(d->m_currentRequest);
+    d->m_curlRequest = createCurlRequest(d->m_firstRequest);
 
-    if (auto credential = getCredential(d->m_currentRequest, false))
+    if (auto credential = getCredential(d->m_firstRequest, false))
         d->m_curlRequest->setUserPass(credential->first, credential->second);
 
     d->m_curlRequest->start();
@@ -111,36 +111,45 @@
     return !client();
 }
 
-Ref<CurlRequest> ResourceHandle::createCurlRequest(ResourceRequest& request)
+void ResourceHandle::addCacheValidationHeaders(ResourceRequest& request)
 {
     ASSERT(isMainThread());
 
-    // CurlCache : append additional cache information
     d->m_addedCacheValidationHeaders = false;
 
-    bool hasCacheHeaders = request.httpHeaderFields().contains(HTTPHeaderName::IfModifiedSince) || request.httpHeaderFields().contains(HTTPHeaderName::IfNoneMatch);
-    if (!hasCacheHeaders) {
-        auto& cache = CurlCacheManager::singleton();
-        URL cacheUrl = request.url();
-        cacheUrl.removeFragmentIdentifier();
+    auto hasCacheHeaders = request.httpHeaderFields().contains(HTTPHeaderName::IfModifiedSince) || request.httpHeaderFields().contains(HTTPHeaderName::IfNoneMatch);
+    if (hasCacheHeaders)
+        return;
 
-        if (cache.isCached(cacheUrl)) {
-            cache.addCacheEntryClient(cacheUrl, this);
+    auto& cache = CurlCacheManager::singleton();
+    URL cacheUrl = request.url();
+    cacheUrl.removeFragmentIdentifier();
 
-            for (const auto& entry : cache.requestHeaders(cacheUrl))
-                request.addHTTPHeaderField(entry.key, entry.value);
+    if (cache.isCached(cacheUrl)) {
+        cache.addCacheEntryClient(cacheUrl, this);
 
-            d->m_addedCacheValidationHeaders = true;
-        }
+        for (const auto& entry : cache.requestHeaders(cacheUrl))
+            request.addHTTPHeaderField(entry.key, entry.value);
+
+        d->m_addedCacheValidationHeaders = true;
     }
+}
 
-    auto& storageSession = NetworkStorageSession::defaultStorageSession();
-    auto& cookieJar = storageSession.cookieStorage();
-    auto includeSecureCookies = request.url().protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;
-    String cookieHeaderField = cookieJar.cookieRequestHeaderFieldValue(storageSession, request.firstPartyForCookies(), request.url(), std::nullopt, std::nullopt, includeSecureCookies).first;
-    if (!cookieHeaderField.isEmpty())
-        request.addHTTPHeaderField(HTTPHeaderName::Cookie, cookieHeaderField);
+Ref<CurlRequest> ResourceHandle::createCurlRequest(ResourceRequest& request, RequestStatus status)
+{
+    ASSERT(isMainThread());
 
+    if (status == RequestStatus::NewRequest) {
+        addCacheValidationHeaders(request);
+
+        auto& storageSession = NetworkStorageSession::defaultStorageSession();
+        auto& cookieJar = storageSession.cookieStorage();
+        auto includeSecureCookies = request.url().protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;
+        String cookieHeaderField = cookieJar.cookieRequestHeaderFieldValue(storageSession, request.firstPartyForCookies(), request.url(), std::nullopt, std::nullopt, includeSecureCookies).first;
+        if (!cookieHeaderField.isEmpty())
+            request.addHTTPHeaderField(HTTPHeaderName::Cookie, cookieHeaderField);
+    }
+
     CurlRequest::ShouldSuspend shouldSuspend = d->m_defersLoading ? CurlRequest::ShouldSuspend::Yes : CurlRequest::ShouldSuspend::No;
     auto curlRequest = CurlRequest::create(request, *delegate(), shouldSuspend, CurlRequest::EnableMultipart::Yes);
     
@@ -361,12 +370,13 @@
     if (!d->m_curlRequest)
         return;
     
-    bool isSyncRequest = d->m_curlRequest->isSyncRequest();
+    auto wasSyncRequest = d->m_curlRequest->isSyncRequest();
+    auto previousRequest = d->m_curlRequest->resourceRequest();
     d->m_curlRequest->cancel();
 
-    d->m_curlRequest = createCurlRequest(d->m_currentRequest);
+    d->m_curlRequest = createCurlRequest(previousRequest, RequestStatus::ReusedRequest);
     d->m_curlRequest->setUserPass(user, password);
-    d->m_curlRequest->start(isSyncRequest);
+    d->m_curlRequest->start(wasSyncRequest);
 }
 
 void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentialsPolicy, ResourceError& error, ResourceResponse& response, Vector<char>& data)
@@ -489,19 +499,17 @@
     if (cancelledOrClientless() || !d->m_curlRequest)
         return;
 
-    d->m_currentRequest = WTFMove(request);
-
-    bool isSyncRequest = d->m_curlRequest->isSyncRequest();
+    auto wasSyncRequest = d->m_curlRequest->isSyncRequest();
     d->m_curlRequest->cancel();
 
-    d->m_curlRequest = createCurlRequest(d->m_currentRequest);
+    d->m_curlRequest = createCurlRequest(request);
 
-    if (protocolHostAndPortAreEqual(d->m_currentRequest.url(), delegate()->response().url())) {
-        if (auto credential = getCredential(d->m_currentRequest, true))
+    if (protocolHostAndPortAreEqual(request.url(), delegate()->response().url())) {
+        if (auto credential = getCredential(request, true))
             d->m_curlRequest->setUserPass(credential->first, credential->second);
     }
 
-    d->m_curlRequest->start(isSyncRequest);
+    d->m_curlRequest->start(wasSyncRequest);
 }
 
 void ResourceHandle::handleDataURL()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to