Commit f25963e5 authored by peter's avatar peter Committed by Commit bot

Set the Content-Type and Content-Length headers for BG Fetch

While we work on being able to relay all response headers from the
download system to the created Response object for Background Fetch,
these two will enable some minimum experimentation.

BUG=692579, 709489

Review-Url: https://codereview.chromium.org/2805813006
Cr-Commit-Position: refs/heads/master@{#462899}
parent d2b71203
......@@ -207,11 +207,21 @@ void BackgroundFetchDataManager::GetSettledFetchesForRegistration(
settled_fetch.request = request->fetch_request();
settled_fetch.response.url_list = request->GetURLChain();
// TODO: settled_fetch.response.status_code
// TODO(peter): The |status_code| should match what the download manager ran
// in to in the BackgroundFetchResponseInfo.
settled_fetch.response.status_code = 200;
// TODO: settled_fetch.response.status_text
settled_fetch.response.response_type =
blink::WebServiceWorkerResponseTypeDefault;
// TODO: settled_fetch.response.headers
// TODO(peter): The |headers| should be set to the real response headers,
// but the download manager does not relay those to us yet.
if (!request->GetResponseType().empty()) {
settled_fetch.response.headers["Content-Type"] =
request->GetResponseType();
}
if (request->GetFileSize() > 0) {
DCHECK(!request->GetFilePath().empty());
......@@ -226,6 +236,10 @@ void BackgroundFetchDataManager::GetSettledFetchesForRegistration(
settled_fetch.response.blob_uuid = blob_handle->GetUUID();
settled_fetch.response.blob_size = request->GetFileSize();
// TODO(peter): Remove when we relay the real response headers.
settled_fetch.response.headers["Content-Length"] =
std::to_string(request->GetFileSize());
blob_handles.push_back(std::move(blob_handle));
}
}
......
......@@ -36,6 +36,7 @@ void BackgroundFetchRequestInfo::PopulateResponseFromDownloadItem(
file_path_ = download_item->GetTargetFilePath();
file_size_ = download_item->GetReceivedBytes();
response_time_ = download_item->GetEndTime();
response_type_ = download_item->GetMimeType();
response_data_populated_ = true;
}
......@@ -60,4 +61,9 @@ const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const {
return response_time_;
}
const std::string& BackgroundFetchRequestInfo::GetResponseType() const {
DCHECK(response_data_populated_);
return response_type_;
}
} // namespace content
......@@ -60,6 +60,9 @@ class CONTENT_EXPORT BackgroundFetchRequestInfo
// Returns the time at which the response was completed.
const base::Time& GetResponseTime() const;
// Returns the mime type describing the response, as indicated by the server.
const std::string& GetResponseType() const;
private:
friend class base::RefCountedThreadSafe<BackgroundFetchRequestInfo>;
......@@ -87,6 +90,7 @@ class CONTENT_EXPORT BackgroundFetchRequestInfo
base::FilePath file_path_;
int64_t file_size_ = 0;
base::Time response_time_;
std::string response_type_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRequestInfo);
};
......
......@@ -369,11 +369,11 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) {
EXPECT_EQ(fetches[i].request.url, fetches[i].response.url_list[0]);
// TODO(peter): change-detector tests for unsupported properties.
EXPECT_EQ(fetches[i].response.status_code, 0);
EXPECT_EQ(fetches[i].response.status_code, 200);
EXPECT_TRUE(fetches[i].response.status_text.empty());
EXPECT_EQ(fetches[i].response.response_type,
blink::WebServiceWorkerResponseTypeDefault);
EXPECT_TRUE(fetches[i].response.headers.empty());
EXPECT_FALSE(fetches[i].response.headers.empty());
EXPECT_EQ(fetches[i].response.error,
blink::WebServiceWorkerResponseErrorUnknown);
......
......@@ -133,6 +133,7 @@ class BackgroundFetchTestBase::RespondingDownloadManager
download_item->SetTargetFilePath(response_path);
download_item->SetReceivedBytes(response_info.second.size());
download_item->SetMimeType("text/plain");
// Notify the Job Controller about the download having been updated.
download_item->NotifyDownloadUpdated();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment