[Curl] Favicons loaded from disc cache are ignored.
authorpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Apr 2015 18:57:13 +0000 (18:57 +0000)
committerpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Apr 2015 18:57:13 +0000 (18:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143953

Reviewed by Alex Christensen.

When a favicon is loaded from the Curl disc cache, the icon data is thrown away.
This happens because we give a 304 response, which makes the icon loader ignore
the response. We can solve this by responding with 200 OK.

* platform/network/ResourceHandleInternal.h:
(WebCore::ResourceHandleInternal::ResourceHandleInternal):
* platform/network/curl/CurlCacheManager.cpp:
(WebCore::CurlCacheManager::didReceiveResponse):
* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::headerCallback):
(WebCore::ResourceHandleManager::initializeHandle):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/ResourceHandleInternal.h
Source/WebCore/platform/network/curl/CurlCacheManager.cpp
Source/WebCore/platform/network/curl/ResourceHandleManager.cpp

index 4be0f34df5746a67ae998363eb8538e16a901a1f..e61cb0328bee49cae83654a72bd00a9ec45f3877 100644 (file)
@@ -1,3 +1,22 @@
+2015-04-27  Per Arne Vollan  <peavo@outlook.com>
+
+        [Curl] Favicons loaded from disc cache are ignored.
+        https://bugs.webkit.org/show_bug.cgi?id=143953
+
+        Reviewed by Alex Christensen.
+
+        When a favicon is loaded from the Curl disc cache, the icon data is thrown away.
+        This happens because we give a 304 response, which makes the icon loader ignore
+        the response. We can solve this by responding with 200 OK.
+
+        * platform/network/ResourceHandleInternal.h:
+        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
+        * platform/network/curl/CurlCacheManager.cpp:
+        (WebCore::CurlCacheManager::didReceiveResponse):
+        * platform/network/curl/ResourceHandleManager.cpp:
+        (WebCore::headerCallback):
+        (WebCore::ResourceHandleManager::initializeHandle):
+
 2015-04-27  Brady Eidson  <beidson@apple.com>
 
         Make 'enum NavigationType' be an enum class
index b0e0359670c1a69a30400fad745948dd14d2bd0b..6bcd5362169dbbd9df6ef41e675a650ebe384b38 100644 (file)
@@ -87,13 +87,7 @@ namespace WebCore {
             , m_currentRequest(request)
 #endif
 #if USE(CURL)
-            , m_handle(0)
-            , m_url(0)
-            , m_customHeaders(0)
-            , m_cancelled(false)
-            , m_authFailureCount(0)
             , m_formDataStream(loader)
-            , m_sslErrors(0)
 #endif
 #if USE(SOUP)
             , m_cancelled(false)
@@ -151,18 +145,19 @@ namespace WebCore {
         RetainPtr<CFURLStorageSessionRef> m_storageSession;
 #endif
 #if USE(CURL)
-        CURL* m_handle;
-        char* m_url;
-        struct curl_slist* m_customHeaders;
+        CURL* m_handle { nullptr };
+        char* m_url { nullptr };
+        struct curl_slist* m_customHeaders { nullptr };
         ResourceResponse m_response;
-        bool m_cancelled;
-        unsigned short m_authFailureCount;
+        bool m_cancelled { false };
+        unsigned short m_authFailureCount { 0 };
 
         FormDataStream m_formDataStream;
-        unsigned m_sslErrors;
+        unsigned m_sslErrors { 0 };
         Vector<char> m_postBytes;
 
         std::unique_ptr<MultipartHandle> m_multipartHandle;
+        bool m_addedCacheValidationHeaders { false };
 #endif
 #if USE(SOUP)
         GRefPtr<SoupMessage> m_soupMessage;
index 4b5677bd45100cf0548ce57bc3b3696fe2d72d2f..052b3987595e7d8f55177d2d095e43e6c7c61788 100644 (file)
@@ -206,7 +206,7 @@ void CurlCacheManager::didReceiveResponse(ResourceHandle& job, ResourceResponse&
 
     removeCacheEntryClient(url, &job);
 
-    if (response.httpStatusCode() == 304) {
+    if (response.source() == ResourceResponseBase::Source::DiskCache) {
         readCachedData(url, &job, response);
         m_LRUEntryList.prependOrMoveToFirst(url);
     }
index fd8f58e88259372fd202bb6297a59dc629ebdfba..a2aece26ded698d84ca58c909135a297be248309 100644 (file)
@@ -553,7 +553,12 @@ static size_t headerCallback(char* ptr, size_t size, size_t nmemb, void* data)
         if (client) {
             if (isHttpNotModified(httpCode)) {
                 const String& url = job->firstRequest().url().string();
-                CurlCacheManager::getInstance().getCachedResponse(url, d->m_response);
+                if (CurlCacheManager::getInstance().getCachedResponse(url, d->m_response)) {
+                    if (d->m_addedCacheValidationHeaders) {
+                        d->m_response.setHTTPStatusCode(200);
+                        d->m_response.setHTTPStatusText("OK");
+                    }
+                }
             }
             client->didReceiveResponse(job, d->m_response);
             CurlCacheManager::getInstance().didReceiveResponse(*job, d->m_response);
@@ -1085,7 +1090,8 @@ void ResourceHandleManager::initializeHandle(ResourceHandle* job)
     if (job->firstRequest().httpHeaderFields().size() > 0) {
         HTTPHeaderMap customHeaders = job->firstRequest().httpHeaderFields();
 
-        if (CurlCacheManager::getInstance().isCached(url)) {
+        bool hasCacheHeaders = customHeaders.contains(HTTPHeaderName::IfModifiedSince) || customHeaders.contains(HTTPHeaderName::IfNoneMatch);
+        if (!hasCacheHeaders && CurlCacheManager::getInstance().isCached(url)) {
             CurlCacheManager::getInstance().addCacheEntryClient(url, job);
             HTTPHeaderMap& requestHeaders = CurlCacheManager::getInstance().requestHeaders(url);
 
@@ -1096,10 +1102,7 @@ void ResourceHandleManager::initializeHandle(ResourceHandle* job)
                 customHeaders.set(it->key, it->value);
                 ++it;
             }
-        } else {
-            // Make sure we don't send any cache headers when url is not cached.
-            customHeaders.remove(HTTPHeaderName::IfModifiedSince);
-            customHeaders.remove(HTTPHeaderName::IfNoneMatch);
+            d->m_addedCacheValidationHeaders = true;
         }
 
         HTTPHeaderMap::const_iterator end = customHeaders.end();