[core] Use better types for modified / expires / etag

This commit is contained in:
John Firebaugh
2016-01-19 15:57:17 -08:00
parent c33ed50c98
commit 1c21d0fd4c
33 changed files with 231 additions and 169 deletions

View File

@@ -124,10 +124,10 @@ HTTPAndroidRequest::HTTPAndroidRequest(HTTPAndroidContext* context_, const std::
std::string etagStr;
std::string modifiedStr;
if (existingResponse) {
if (!existingResponse->etag.empty()) {
etagStr = existingResponse->etag;
} else if (existingResponse->modified != Seconds::zero()) {
modifiedStr = util::rfc1123(existingResponse->modified.count());
if (existingResponse->etag) {
etagStr = *existingResponse->etag;
} else if (existingResponse->modified) {
modifiedStr = util::rfc1123(SystemClock::to_time_t(*existingResponse->modified));
}
}
@@ -195,11 +195,11 @@ void HTTPAndroidRequest::onResponse(int code, std::string message, std::string e
// the message param is unused, this generates a warning at build time
// this was breaking builds for `make android -j4`
(void)message;
response->modified = Seconds(parse_date(modified.c_str()));
response->modified = SystemClock::from_time_t(parse_date(modified.c_str()));
response->etag = etag;
response->expires = parseCacheControl(cacheControl.c_str());
if (!expires.empty()) {
response->expires = Seconds(parse_date(expires.c_str()));
response->expires = SystemClock::from_time_t(parse_date(expires.c_str()));
}
response->data = std::make_shared<std::string>(body);
@@ -211,15 +211,15 @@ void HTTPAndroidRequest::onResponse(int code, std::string message, std::string e
if (existingResponse) {
response->data = existingResponse->data;
if (response->expires == Seconds::zero()) {
if (!response->expires) {
response->expires = existingResponse->expires;
}
if (response->modified == Seconds::zero()) {
if (!response->modified) {
response->modified = existingResponse->modified;
}
if (response->etag.empty()) {
if (!response->etag) {
response->etag = existingResponse->etag;
}
}