[core] Replace time_t with std::chrono::seconds

Added aliases for std::chrono typedefs (eg. 'Seconds' for
std::chrono::seconds). These aliases are used together with templated
helper functions to replace time_t with std::chrono::seconds for most
cases, in particular for 'modified' and 'expires' values in Response.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-25 13:30:32 +02:00
parent 4475f54860
commit 31fd2822f5
30 changed files with 184 additions and 121 deletions

View File

@@ -425,9 +425,9 @@ HTTPCURLRequest::HTTPCURLRequest(HTTPCURLContext* context_, const Resource& reso
if (!existingResponse->etag.empty()) {
const std::string header = std::string("If-None-Match: ") + existingResponse->etag;
headers = curl_slist_append(headers, header.c_str());
} else if (existingResponse->modified) {
} else if (existingResponse->modified != Seconds::zero()) {
const std::string time =
std::string("If-Modified-Since: ") + util::rfc1123(existingResponse->modified);
std::string("If-Modified-Since: ") + util::rfc1123(existingResponse->modified.count());
headers = curl_slist_append(headers, time.c_str());
}
}
@@ -525,7 +525,7 @@ size_t HTTPCURLRequest::headerCallback(char *const buffer, const size_t size, co
// Always overwrite the modification date; We might already have a value here from the
// Date header, but this one is more accurate.
const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n
baton->response->modified = curl_getdate(value.c_str(), nullptr);
baton->response->modified = Seconds(curl_getdate(value.c_str(), nullptr));
} else if ((begin = headerMatches("etag: ", buffer, length)) != std::string::npos) {
baton->response->etag = { buffer + begin, length - begin - 2 }; // remove \r\n
} else if ((begin = headerMatches("cache-control: ", buffer, length)) != std::string::npos) {
@@ -533,7 +533,7 @@ size_t HTTPCURLRequest::headerCallback(char *const buffer, const size_t size, co
baton->response->expires = parseCacheControl(value.c_str());
} else if ((begin = headerMatches("expires: ", buffer, length)) != std::string::npos) {
const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n
baton->response->expires = curl_getdate(value.c_str(), nullptr);
baton->response->expires = Seconds(curl_getdate(value.c_str(), nullptr));
}
return length;