diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-19 15:57:17 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-21 11:22:11 -0800 |
commit | 1c21d0fd4cd30cbf6c5b863fd0179b227c28bc0b (patch) | |
tree | dfb6b788285d2b28f7060138ae28734ece13942e /platform/default/http_request_curl.cpp | |
parent | c33ed50c98c57ce2f2cf3b971bcf72c4208bf120 (diff) | |
download | qtlocation-mapboxgl-1c21d0fd4cd30cbf6c5b863fd0179b227c28bc0b.tar.gz |
[core] Use better types for modified / expires / etag
Diffstat (limited to 'platform/default/http_request_curl.cpp')
-rw-r--r-- | platform/default/http_request_curl.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp index f5fc395862..078a172c2b 100644 --- a/platform/default/http_request_curl.cpp +++ b/platform/default/http_request_curl.cpp @@ -363,12 +363,12 @@ HTTPCURLRequest::HTTPCURLRequest(HTTPCURLContext* context_, const std::string& u // If there's already a response, set the correct etags/modified headers to make sure we are // getting a 304 response if possible. This avoids redownloading unchanged data. if (existingResponse) { - if (!existingResponse->etag.empty()) { - const std::string header = std::string("If-None-Match: ") + existingResponse->etag; + if (existingResponse->etag) { + const std::string header = std::string("If-None-Match: ") + *existingResponse->etag; headers = curl_slist_append(headers, header.c_str()); - } else if (existingResponse->modified != Seconds::zero()) { + } else if (existingResponse->modified) { const std::string time = - std::string("If-Modified-Since: ") + util::rfc1123(existingResponse->modified.count()); + std::string("If-Modified-Since: ") + util::rfc1123(SystemClock::to_time_t(*existingResponse->modified)); headers = curl_slist_append(headers, time.c_str()); } } @@ -466,15 +466,15 @@ 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 = Seconds(curl_getdate(value.c_str(), nullptr)); + baton->response->modified = SystemClock::from_time_t(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 + baton->response->etag = std::string(buffer + begin, length - begin - 2); // remove \r\n } else if ((begin = headerMatches("cache-control: ", buffer, length)) != std::string::npos) { const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n 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 = Seconds(curl_getdate(value.c_str(), nullptr)); + baton->response->expires = SystemClock::from_time_t(curl_getdate(value.c_str(), nullptr)); } return length; @@ -534,15 +534,15 @@ void HTTPCURLRequest::handleResult(CURLcode code) { 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; } } |