commit 282d49de701e61eb9e3335e01dd1bcf546ae8786
parent 4ab51d84f7fe5958979dce201d9ed98086f0fe8b
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 10 Aug 2016 20:35:54 -0400
ask the remote server or proxy for a fresh copy of the index files (bypass cache)
Diffstat:
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/download.cpp b/src/download.cpp
@@ -40,8 +40,10 @@ void Download::Cleanup()
curl_global_cleanup();
}
-Download::Download(const string &name, const string &url, const NetworkOpts &opts)
- : m_name(name), m_url(url), m_opts(opts), m_threadHandle(nullptr)
+Download::Download(const string &name, const string &url,
+ const NetworkOpts &opts, const int flags)
+ : m_name(name), m_url(url), m_opts(opts),
+ m_flags(flags), m_threadHandle(nullptr)
{
reset();
}
@@ -128,16 +130,26 @@ DWORD WINAPI Download::Worker(void *ptr)
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, download);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, UpdateProgress);
+ curl_slist *headers = nullptr;
+ if(download->has(NoCacheFlag))
+ headers = curl_slist_append(headers, "Cache-Control: no-cache");
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+
const CURLcode res = curl_easy_perform(curl);
+ const auto cleanup = [=] {
+ curl_slist_free_all(headers);
+ curl_easy_cleanup(curl);
+ };
+
if(download->isAborted()) {
download->finish(Aborted, "aborted by user");
- curl_easy_cleanup(curl);
+ cleanup();
return 1;
}
else if(res != CURLE_OK) {
download->finish(Failure, curl_easy_strerror(res));
- curl_easy_cleanup(curl);
+ cleanup();
return 1;
}
@@ -166,7 +178,7 @@ DWORD WINAPI Download::Worker(void *ptr)
break;
}
- curl_easy_cleanup(curl);
+ cleanup();
return 0;
}
diff --git a/src/download.hpp b/src/download.hpp
@@ -44,15 +44,21 @@ public:
Aborted,
};
+ enum Flag {
+ NoCacheFlag = 1<<0,
+ };
+
static void Init();
static void Cleanup();
- Download(const std::string &name, const std::string &url, const NetworkOpts &);
+ Download(const std::string &name, const std::string &url,
+ const NetworkOpts &, int flags = 0);
~Download();
const std::string &name() const { return m_name; }
const std::string &url() const { return m_url; }
const NetworkOpts &options() const { return m_opts; }
+ bool has(Flag f) const { return (m_flags & f) != 0; }
State state();
const std::string &contents();
@@ -88,6 +94,7 @@ private:
std::string m_name;
std::string m_url;
NetworkOpts m_opts;
+ int m_flags;
WDL_Mutex m_mutex;
diff --git a/src/index.cpp b/src/index.cpp
@@ -94,7 +94,8 @@ Download *Index::fetch(const Remote &remote,
return nullptr;
}
- return new Download(remote.name() + ".xml", remote.url(), opts);
+ return new Download(remote.name() + ".xml", remote.url(),
+ opts, Download::NoCacheFlag);
}
Index::Index(const string &name)