Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp

Issue 1558703002: Synchronous requests that get a 304 clobber the cached response body. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/cache/sync-xhr-304-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp b/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp
index 0c6b3611c2b427cdc9156678b8d948ea885aeda8..a3ae8717540a5edba593bc480e1399bdefff9679 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceLoader.cpp
@@ -515,8 +515,15 @@ void ResourceLoader::requestSynchronously()
return;
RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse().resourceLoadInfo();
int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLength : WebURLLoaderClient::kUnknownEncodedDataLength;
- m_fetcher->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDataLength);
- m_resource->setResourceBuffer(dataOut);
+
+ // Follow the async case convention of not calling didReceiveData or
+ // appending data to m_resource if the response body is empty. Copying the
+ // empty buffer is a noop in most cases, but is destructive in the case of
+ // a 304, where it will overwrite the cached data we should be reusing.
+ if (dataOut.size()) {
+ m_fetcher->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDataLength);
+ m_resource->setResourceBuffer(dataOut);
+ }
didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
}
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/cache/sync-xhr-304-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698