Allow market data replayer to use the cached file if the http server is unavailable or a teapot
This commit is contained in:
1 parent
e5369ac8f1
commit
5f38a4b203
1 file changed
+7
-3
@@ -27,6 +27,7 @@ int read_headers(istream& input, map<string, string>& result) {
|
||||
auto code_end = line.find_first_of(" ", code_start+1);
|
||||
string http_code = line.substr(code_start+1, (code_end - code_start - 1));
|
||||
boost::algorithm::trim(http_code);
|
||||
if (http_code.empty()) return 418;
|
||||
while(true) {
|
||||
std::getline(input, line);
|
||||
auto index = line.find_first_of(" ");
|
||||
@@ -70,9 +71,12 @@ bool download_file_if_newer(const string& host, const string& path, const string
|
||||
HTTPStream download(host, path, "GET");
|
||||
tm modtm = boost::initialized_value;
|
||||
const char* rfc_1123_fmt = "%a, %d %b %Y %H:%M:%S %Z";
|
||||
stringstream ss(download.headers().at("Last-Modified"));
|
||||
ss >> std::get_time(&modtm, rfc_1123_fmt);
|
||||
time_t modified = mktime(&modtm);
|
||||
time_t modified = 0;
|
||||
if (download.good()) {
|
||||
stringstream ss(download.headers().at("Last-Modified"));
|
||||
ss >> std::get_time(&modtm, rfc_1123_fmt);
|
||||
modified = mktime(&modtm);
|
||||
}
|
||||
|
||||
// If our file mtime is newer do not download
|
||||
if (difftime(modified, st.st_mtime) > 0) {
|
||||
|
||||
Reference in new issue
Block a user