From 53c1a7bcfa327b1963c9b14ef240aecb764166c8 Mon Sep 17 00:00:00 2001 From: Viraj Alankar Date: Fri, 6 Sep 2024 15:36:54 +0000 Subject: [PATCH 1/2] Disable caching for dynamic page. --- app/http/routes/strategies.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/http/routes/strategies.go b/app/http/routes/strategies.go index d390de04..b699a383 100644 --- a/app/http/routes/strategies.go +++ b/app/http/routes/strategies.go @@ -90,6 +90,7 @@ func (s *ServeStrategy) ServeDynamic(c *gin.Context) { } writer.Flush() + c.Header("Cache-Control", "no-cache") c.Header("Content-Type", "text/html") c.Header("Content-Length", strconv.Itoa(buf.Len())) c.Writer.Write(buf.Bytes()) From 4d46d5bb3ae4bcf0f17bca5409dc9fb71c6a1507 Mon Sep 17 00:00:00 2001 From: Viraj Alankar Date: Fri, 6 Sep 2024 16:23:28 +0000 Subject: [PATCH 2/2] Add test for Cache-Control header. --- app/http/routes/strategies_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/http/routes/strategies_test.go b/app/http/routes/strategies_test.go index 34afa2de..40b5ea7d 100644 --- a/app/http/routes/strategies_test.go +++ b/app/http/routes/strategies_test.go @@ -73,6 +73,24 @@ func TestServeStrategy_ServeDynamic(t *testing.T) { expectedHeaderKey: "X-Sablier-Session-Status", expectedHeaderValue: "not-ready", }, + { + name: "header requests no caching", + arg: arg{ + body: models.DynamicRequest{ + Names: []string{"nginx"}, + DisplayName: "Test", + Theme: "hacker-terminal", + SessionDuration: 1 * time.Minute, + }, + session: sessions.SessionState{ + Instances: createMap([]*instance.State{ + {Name: "nginx", Status: instance.NotReady}, + }), + }, + }, + expectedHeaderKey: "Cache-Control", + expectedHeaderValue: "no-cache", + }, { name: "header has ready value when session is ready", arg: arg{ @@ -104,7 +122,7 @@ func TestServeStrategy_ServeDynamic(t *testing.T) { SessionState: tt.arg.session, }, StrategyConfig: config.NewStrategyConfig(), - Theme: theme, + Theme: theme, } recorder := httptest.NewRecorder() c := GetTestGinContext(recorder)