Skip to content

Commit 93f95f4

Browse files
linevbellenot
authored andcommitted
http: let configure NoCache header directly in THttpCallArg
Reused in many places
1 parent 679d9c9 commit 93f95f4

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

net/http/inc/THttpCallArg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class THttpCallArg : public TObject {
186186

187187
void AddHeader(const char *name, const char *value);
188188

189+
void AddNoCacheHeader();
190+
189191
/** returns number of fields in header */
190192
Int_t NumHeader() const { return CountHeader(fHeader).Atoi(); }
191193

net/http/src/TCivetweb.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static int begin_request_handler(struct mg_connection *conn, void *)
244244
if (engine->GetMaxAge() > 0)
245245
arg->AddHeader("Cache-Control", TString::Format("max-age=%d", engine->GetMaxAge()));
246246
else
247-
arg->AddHeader("Cache-Control", "private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
247+
arg->AddNoCacheHeader();
248248
arg->SetZipping();
249249
}
250250
} else {

net/http/src/THttpCallArg.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ void THttpCallArg::AddHeader(const char *name, const char *value)
346346
AccessHeader(fHeader, name, value, kTRUE);
347347
}
348348

349+
////////////////////////////////////////////////////////////////////////////////
350+
/// Set CacheControl http header to disable browser caching
351+
352+
void THttpCallArg::AddNoCacheHeader()
353+
{
354+
AddHeader("Cache-Control", "private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
355+
}
356+
349357
////////////////////////////////////////////////////////////////////////////////
350358
/// Fills HTTP header, which can be send at the beggining of reply on the http request
351359
/// \param name is HTTP protocol name (default "HTTP/1.1")

net/http/src/THttpServer.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ void THttpServer::ProcessRequest(THttpCallArg *arg)
846846
fname.ReplaceAll("$jsrootsys", fJSROOTSYS);
847847

848848
arg->fContent = ReadFileContent(fname.Data());
849+
arg->AddNoCacheHeader();
849850
}
850851
}
851852

@@ -882,8 +883,8 @@ void THttpServer::ProcessRequest(THttpCallArg *arg)
882883

883884
arg->ReplaceAllinContent(hjsontag, h_json.Data());
884885

885-
arg->AddHeader("Cache-Control",
886-
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
886+
arg->AddNoCacheHeader();
887+
887888
if (arg->fQuery.Index("nozip") == kNPOS)
888889
arg->SetZipping();
889890
}
@@ -931,8 +932,7 @@ void THttpServer::ProcessRequest(THttpCallArg *arg)
931932
if (fSniffer->Produce(arg->fPathName.Data(), "root.json", "compact=23", str))
932933
arg->ReplaceAllinContent(rootjsontag, str);
933934
}
934-
arg->AddHeader("Cache-Control",
935-
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
935+
arg->AddNoCacheHeader();
936936
if (arg->fQuery.Index("nozip") == kNPOS)
937937
arg->SetZipping();
938938
arg->SetContentType("text/html");
@@ -1017,8 +1017,7 @@ void THttpServer::ProcessRequest(THttpCallArg *arg)
10171017
}
10181018

10191019
// try to avoid caching on the browser
1020-
arg->AddHeader("Cache-Control",
1021-
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
1020+
arg->AddNoCacheHeader();
10221021

10231022
// potentially add cors header
10241023
if (IsCors())

0 commit comments

Comments
 (0)