in src/dcap_provider.cpp [341:387]
bool get_cache_expiration_time(const string& cache_control, const string& url, time_t& expiration_time)
{
time_t max_age = 0;
tm* max_age_s = localtime(&max_age);
size_t index = cache_control.find(CACHE_CONTROL_MAX_AGE);
int cache_time_seconds = 0;
constexpr int MAX_CACHE_TIME_SECONDS = 86400;
if (index != string::npos)
{
try
{
cache_time_seconds = stoi(cache_control.substr(index + CACHE_CONTROL_MAX_AGE.length()));
if (cache_time_seconds > MAX_CACHE_TIME_SECONDS)
{
log(SGX_QL_LOG_ERROR,
"Caching control '%d' larger than maximum '%d' seconds. Collateral will not be cached",
cache_time_seconds,
MAX_CACHE_TIME_SECONDS);
return false;
}
}
catch (const std::invalid_argument& e)
{
log(SGX_QL_LOG_ERROR,
"Invalid argument thrown when parsing cache-control. Header text: '%s' Error: '%s'. Collateral will not be cached",
cache_control.c_str(),
e.what());
return false;
}
catch (const std::out_of_range& e)
{
log(SGX_QL_LOG_ERROR,
"Invalid argument thrown when parsing cache-control. Header text: '%s' Error: '%s'. Collateral will not be cached",
cache_control.c_str(),
e.what());
return false;
}
}
max_age_s->tm_sec += cache_time_seconds;
expiration_time = time(nullptr) + mktime(max_age_s);
log(SGX_QL_LOG_INFO,
"Caching collateral '%s' for '%d' seconds",
url.c_str(),
cache_time_seconds);
return true;
}