Skip to content
Snippets Groups Projects
Commit 4db1c98b authored by Sergey Linev's avatar Sergey Linev
Browse files

[http] redirect to jsrootsys from main server folder

When different subtimes want to load JSROOT, only central
version will be accessed. Let properly use browser cache
when desired
parent bf437b44
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,8 @@ protected: ...@@ -68,6 +68,8 @@ protected:
std::string BuildWSEntryPage(); std::string BuildWSEntryPage();
void ReplaceJSROOTLinks(std::shared_ptr<THttpCallArg> &arg);
static Bool_t VerifyFilePath(const char *fname); static Bool_t VerifyFilePath(const char *fname);
THttpServer(const THttpServer &) = delete; THttpServer(const THttpServer &) = delete;
......
...@@ -743,6 +743,45 @@ std::string THttpServer::BuildWSEntryPage() ...@@ -743,6 +743,45 @@ std::string THttpServer::BuildWSEntryPage()
return res; return res;
} }
////////////////////////////////////////////////////////////////////////////////
/// Replaces all references like "jsrootsys/..."
/// Either using pre-configured JSROOT installation from web or
/// redirect to jsrootsys from the main server path to benefit from browser caching
void THttpServer::ReplaceJSROOTLinks(std::shared_ptr<THttpCallArg> &arg)
{
std::string repl;
if (fJSROOT.Length() > 0) {
repl = "=\"";
repl.append(fJSROOT.Data());
if (repl.back() != '/')
repl.append("/");
} else {
Int_t cnt = 0;
if (arg->fPathName.Length() > 0) cnt++;
for (Int_t n = 1; n < arg->fPathName.Length()-1; ++n)
if (arg->fPathName[n] == '/') {
if (arg->fPathName[n-1] != '/') {
cnt++; // normal slash in the middle, count it
} else {
cnt = 0; // double slash, do not touch such path
break;
}
}
if (cnt > 0) {
repl = "=\"";
while (cnt-- >0) repl.append("../");
repl.append("jsrootsys/");
}
}
if (!repl.empty())
arg->ReplaceAllinContent("=\"jsrootsys/", repl);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Process single http request /// Process single http request
/// Depending from requested path and filename different actions will be performed. /// Depending from requested path and filename different actions will be performed.
...@@ -808,14 +847,8 @@ void THttpServer::ProcessRequest(std::shared_ptr<THttpCallArg> arg) ...@@ -808,14 +847,8 @@ void THttpServer::ProcessRequest(std::shared_ptr<THttpCallArg> arg)
arg->Set404(); arg->Set404();
} else if (!arg->Is404()) { } else if (!arg->Is404()) {
// replace all references on JSROOT
if (fJSROOT.Length() > 0) { ReplaceJSROOTLinks(arg);
std::string repl("=\"");
repl.append(fJSROOT.Data());
if (repl.back() != '/')
repl.append("/");
arg->ReplaceAllinContent("=\"jsrootsys/", repl);
}
const char *hjsontag = "\"$$$h.json$$$\""; const char *hjsontag = "\"$$$h.json$$$\"";
...@@ -852,14 +885,7 @@ void THttpServer::ProcessRequest(std::shared_ptr<THttpCallArg> arg) ...@@ -852,14 +885,7 @@ void THttpServer::ProcessRequest(std::shared_ptr<THttpCallArg> arg)
arg->fContent = fDrawPageCont; arg->fContent = fDrawPageCont;
// replace all references on JSROOT ReplaceJSROOTLinks(arg);
if (fJSROOT.Length() > 0) {
std::string repl("=\"");
repl.append(fJSROOT.Data());
if (repl.back() != '/')
repl.append("/");
arg->ReplaceAllinContent("=\"jsrootsys/", repl);
}
if ((arg->fQuery.Index("no_h_json") == kNPOS) && (arg->fQuery.Index("webcanvas") == kNPOS) && if ((arg->fQuery.Index("no_h_json") == kNPOS) && (arg->fQuery.Index("webcanvas") == kNPOS) &&
(arg->fContent.find(hjsontag) != std::string::npos)) { (arg->fContent.find(hjsontag) != std::string::npos)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment