# HG changeset patch # User Sebastien Jodogne # Date 1467450985 -7200 # Node ID 8856f15b3e02764d95df1fe366527b859865cce6 # Parent e12d83e9ee59c80cb583445d8c86ac2b56bf3475 disabling cache in ServeFolders diff -r e12d83e9ee59 -r 8856f15b3e02 Plugins/Samples/ServeFolders/Plugin.cpp --- a/Plugins/Samples/ServeFolders/Plugin.cpp Thu Jun 30 20:17:07 2016 +0200 +++ b/Plugins/Samples/ServeFolders/Plugin.cpp Sat Jul 02 11:16:25 2016 +0200 @@ -28,6 +28,19 @@ static OrthancPluginContext* context_ = NULL; static std::map folders_; static const char* INDEX_URI = "/app/plugin-serve-folders.html"; +static bool allowCache_ = true; + + +static void SetHttpHeaders(OrthancPluginRestOutput* output) +{ + if (!allowCache_) + { + // http://stackoverflow.com/a/2068407/881731 + OrthancPluginSetHttpHeader(context_, output, "Cache-Control", "no-cache, no-store, must-revalidate"); + OrthancPluginSetHttpHeader(context_, output, "Pragma", "no-cache"); + OrthancPluginSetHttpHeader(context_, output, "Expires", "0"); + } +} static const char* GetMimeType(const std::string& path) @@ -57,7 +70,8 @@ { return "image/svg+xml"; } - else if (extension == ".json") + else if (extension == ".json" || + extension == ".nmf") { return "application/json"; } @@ -69,7 +83,8 @@ { return "image/png"; } - else if (extension == ".jpg" || extension == ".jpeg") + else if (extension == ".jpg" || + extension == ".jpeg") { return "image/jpeg"; } @@ -77,6 +92,14 @@ { return "application/x-font-woff"; } + else if (extension == ".pexe") + { + return "application/x-pnacl"; + } + else if (extension == ".nexe") + { + return "application/x-nacl"; + } else { std::string s = "Unknown MIME type for extension: " + extension; @@ -212,6 +235,7 @@ s += " \n"; s += "\n"; + SetHttpHeaders(output); OrthancPluginAnswerBuffer(context_, output, s.c_str(), s.size(), "text/html"); } else @@ -223,6 +247,7 @@ if (ReadFile(s, path)) { const char* resource = s.size() ? s.c_str() : NULL; + SetHttpHeaders(output); OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime); } else @@ -269,6 +294,7 @@ s += "\n"; + SetHttpHeaders(output); OrthancPluginAnswerBuffer(context_, output, s.c_str(), s.size(), "text/html"); return OrthancPluginErrorCode_Success; @@ -302,6 +328,12 @@ return -1; } + if (configuration.isMember("ServeFoldersNoCache")) + { + OrthancPluginLogWarning(context_, "Disabling the cache"); + allowCache_ = false; + } + if (configuration.isMember("ServeFolders")) { if (configuration["ServeFolders"].type() != Json::objectValue)