Skip to content

Commit

Permalink
added no-cache for 404 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
semako committed May 21, 2024
1 parent bd49f2a commit d22b0e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/s3-proxy/response-handler/error-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func (h *handler) NotFoundError(
// Get configuration
cfg := h.cfgManager.GetConfig()

// force no-cache headers for 404 status codes
h.res.Header().Set("Cache-Control", "no-cache, no-store, no-transform, must-revalidate, private, max-age=0")

// Create specific error
err := errors.New("Not Found")

Expand Down
52 changes: 52 additions & 0 deletions pkg/s3-proxy/server/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,58 @@ func TestPublicRouter(t *testing.T) {
"X-Accel-Expires": "0",
},
},
{
name: "GET a file with cache management enabled, but not found",
args: args{
cfg: &config.Config{
Server: &config.ServerConfig{
Cache: &config.CacheConfig{
Expires: "expires",
CacheControl: "must-revalidate, max-age=0",
Pragma: "pragma",
XAccelExpires: "xaccelexpires",
},
Compress: svrCfg.Compress,
},
ListTargets: &config.ListTargetsConfig{},
Tracing: tracingConfig,
Templates: testsDefaultGeneralTemplateConfig,
Targets: map[string]*config.TargetConfig{
"target1": {
Name: "target1",
Bucket: &config.BucketConfig{
Name: bucket,
Region: region,
S3Endpoint: s3server.URL,
Credentials: &config.BucketCredentialConfig{
AccessKey: &config.CredentialConfig{Value: accessKey},
SecretKey: &config.CredentialConfig{Value: secretAccessKey},
},
DisableSSL: true,
},
Mount: &config.MountConfig{
Path: []string{"/mount/"},
},
Actions: &config.ActionsConfig{
GET: &config.GetActionConfig{Enabled: true},
},
},
},
},
},
inputMethod: "GET",
inputURL: "http://localhost/mount/folder1/test.txt-not-existing",
expectedCode: 404,
expectedBody: `<!DOCTYPE html>
<html>
<body>
<h1>Not Found /mount/folder1/test.txt-not-existing</h1>
</body>
</html>`,
expectedHeaders: map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
},
},
{
name: "GET a file with cache management enabled",
args: args{
Expand Down

0 comments on commit d22b0e9

Please sign in to comment.