diff options
author | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 21:13:20 +0000 |
---|---|---|
committer | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-19 21:13:20 +0000 |
commit | fdeb7a81b13e68dae850a7d56347fa6a13405815 (patch) | |
tree | 13e8f453223a4637f5f1049d66d1e18f394ec4e7 /webkit/fileapi | |
parent | a1ce752721b6e3c5307a1a202ae01b9a26f442cb (diff) | |
download | chromium_src-fdeb7a81b13e68dae850a7d56347fa6a13405815.zip chromium_src-fdeb7a81b13e68dae850a7d56347fa6a13405815.tar.gz chromium_src-fdeb7a81b13e68dae850a7d56347fa6a13405815.tar.bz2 |
Add 'Cache-Control: no-cache' to filesystem: responses to avoid
having them improperly cached in WebKit's memory cache.
Note that this change as currently written may be unnecessarily
bad for performance, since the file must be read from disk on
every access. For some use cases, this could be quite expensive.
The right fix is probably to put a 'Last-Modified' header in the
response along with 'Cache-Control: max-age: 0', but for now
I'm favoring correctness over performance.
R=michaeln@chromium.org
BUG=79539
TEST=layout test at http://webkit.org/b/58854
Review URL: http://codereview.chromium.org/6879022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82156 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_url_request_job.cc | 32 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_request_job.h | 6 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_request_job_unittest.cc | 4 |
3 files changed, 39 insertions, 3 deletions
diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc index 3eb0842..81f6939 100644 --- a/webkit/fileapi/file_system_url_request_job.cc +++ b/webkit/fileapi/file_system_url_request_job.cc @@ -16,6 +16,8 @@ #include "net/base/mime_util.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" +#include "net/http/http_response_headers.h" +#include "net/http/http_response_info.h" #include "net/http/http_util.h" #include "net/url_request/url_request.h" #include "webkit/fileapi/file_system_path_manager.h" @@ -31,6 +33,22 @@ static const int kFileFlags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC; +static net::HttpResponseHeaders* CreateHttpResponseHeaders() { + // HttpResponseHeaders expects its input string to be terminated by two NULs. + static const char kStatus[] = "HTTP/1.1 200 OK\0"; + static const size_t kStatusLen = arraysize(kStatus); + + net::HttpResponseHeaders* headers = + new net::HttpResponseHeaders(std::string(kStatus, kStatusLen)); + + // Tell WebKit never to cache this content. + std::string cache_control(net::HttpRequestHeaders::kCacheControl); + cache_control.append(": no-cache"); + headers->AddHeader(cache_control); + + return headers; +} + FileSystemURLRequestJob::FileSystemURLRequestJob( URLRequest* request, FileSystemPathManager* path_manager, scoped_refptr<base::MessageLoopProxy> file_thread_proxy) @@ -130,6 +148,17 @@ void FileSystemURLRequestJob::SetExtraRequestHeaders( } } +void FileSystemURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { + if (response_info_.get()) + *info = *response_info_; +} + +int FileSystemURLRequestJob::GetResponseCode() const { + if (response_info_.get()) + return 200; + return URLRequestJob::GetResponseCode(); +} + void FileSystemURLRequestJob::StartAsync() { GURL origin_url; FileSystemType type; @@ -212,6 +241,9 @@ void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code, } set_expected_content_size(remaining_bytes_); + response_info_.reset(new net::HttpResponseInfo()); + response_info_->headers = CreateHttpResponseHeaders(); + NotifyHeadersComplete(); } diff --git a/webkit/fileapi/file_system_url_request_job.h b/webkit/fileapi/file_system_url_request_job.h index ffef027..6d0f6e3 100644 --- a/webkit/fileapi/file_system_url_request_job.h +++ b/webkit/fileapi/file_system_url_request_job.h @@ -40,13 +40,12 @@ class FileSystemURLRequestJob : public net::URLRequestJob { virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); virtual bool IsRedirectResponse(GURL* location, int* http_status_code); virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers); + virtual void GetResponseInfo(net::HttpResponseInfo* info); + virtual int GetResponseCode() const; // FilterContext methods (via URLRequestJob): virtual bool GetMimeType(std::string* mime_type) const; - // TODO(adamk): Implement GetResponseInfo and GetResponseCode to simulate - // an HTTP response. - private: virtual ~FileSystemURLRequestJob(); @@ -68,6 +67,7 @@ class FileSystemURLRequestJob : public net::URLRequestJob { net::CompletionCallbackImpl<FileSystemURLRequestJob> io_callback_; scoped_ptr<net::FileStream> stream_; bool is_directory_; + scoped_ptr<net::HttpResponseInfo> response_info_; net::HttpByteRange byte_range_; int64 remaining_bytes_; diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc index 2a5938f..18b74e0 100644 --- a/webkit/fileapi/file_system_url_request_job_unittest.cc +++ b/webkit/fileapi/file_system_url_request_job_unittest.cc @@ -157,6 +157,10 @@ TEST_F(FileSystemURLRequestJobTest, FileTest) { EXPECT_EQ(1, delegate_->response_started_count()); EXPECT_FALSE(delegate_->received_data_before_response()); EXPECT_EQ(kTestFileData, delegate_->data_received()); + EXPECT_EQ(200, request_->GetResponseCode()); + std::string cache_control; + request_->GetResponseHeaderByName("cache-control", &cache_control); + EXPECT_EQ("no-cache", cache_control); } TEST_F(FileSystemURLRequestJobTest, FileTestFullSpecifiedRange) { |