Mercurial > hg > orthanc
changeset 2061:8856f15b3e02
disabling cache in ServeFolders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 02 Jul 2016 11:16:25 +0200 |
parents | e12d83e9ee59 |
children | 40ffd0e8676a |
files | Plugins/Samples/ServeFolders/Plugin.cpp |
diffstat | 1 files changed, 34 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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<std::string, std::string> 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 += " </body>\n"; s += "</html>\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 += "</body></html>\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)