void OnlineFileRequest::completed(Response response) { // If we didn't get various caching headers in the response, continue using the // previous values. Otherwise, update the previous values to the new values. if (!response.modified) { response.modified = resource.priorModified; } else { resource.priorModified = response.modified; } if (response.notModified && resource.priorData) { // When the priorData field is set, it indicates that we had to revalidate the request and // that the requestor hasn't gotten data yet. If we get a 304 response, this means that we // have send the cached data to give the requestor a chance to actually obtain the data. response.data = std::move(resource.priorData); response.notModified = false; } bool isExpired = false; if (response.expires) { auto prior = resource.priorExpires; resource.priorExpires = response.expires; response.expires = interpolateExpiration(*response.expires, prior, isExpired); } if (isExpired) { expiredRequests++; } else { expiredRequests = 0; } if (!response.etag) { response.etag = resource.priorEtag; } else { resource.priorEtag = response.etag; } if (response.error) { failedRequests++; failedRequestReason = response.error->reason; retryAfter = response.error->retryAfter; } else { failedRequests = 0; failedRequestReason = Response::Error::Reason::Success; } schedule(response.expires); // Calling the callback may result in `this` being deleted. It needs to be done last, // and needs to make a local copy of the callback to ensure that it remains valid for // the duration of the call. auto callback_ = callback; callback_(response); }
void OnlineFileRequest::completed(Response response) { // If we didn't get various caching headers in the response, continue using the // previous values. Otherwise, update the previous values to the new values. if (!response.modified) { response.modified = resource.priorModified; } else { resource.priorModified = response.modified; } bool isExpired = false; if (response.expires) { auto prior = resource.priorExpires; resource.priorExpires = response.expires; response.expires = interpolateExpiration(*response.expires, prior, isExpired); } if (isExpired) { expiredRequests++; } else { expiredRequests = 0; } if (!response.etag) { response.etag = resource.priorEtag; } else { resource.priorEtag = response.etag; } if (response.error) { failedRequests++; failedRequestReason = response.error->reason; retryAfter = response.error->retryAfter; } else { failedRequests = 0; failedRequestReason = Response::Error::Reason::Success; } schedule(response.expires); // Calling the callback may result in `this` being deleted. It needs to be done last, // and needs to make a local copy of the callback to ensure that it remains valid for // the duration of the call. auto callback_ = callback; callback_(response); }