mirror of
https://github.com/sablierapp/sablier.git
synced 2026-01-04 03:54:56 +01:00
fix(api): add Cache-Control header on dynamic page to prevent caching by services like Cloudflare. (#389)
* Disable caching for dynamic page. * Add test for Cache-Control header.
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user