summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/file_system_url_request_job.cc32
-rw-r--r--webkit/fileapi/file_system_url_request_job.h6
-rw-r--r--webkit/fileapi/file_system_url_request_job_unittest.cc4
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) {