From b17b3719958c3fb21d6a8b0d3d951a4f1688f014 Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Tue, 19 Aug 2025 09:16:30 -0400 Subject: [PATCH] [http/s3] support `if-modified-since` and `if-none-match` --- http/route_action_s3.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/http/route_action_s3.go b/http/route_action_s3.go index 3ab3647..4e5b6ee 100644 --- a/http/route_action_s3.go +++ b/http/route_action_s3.go @@ -6,6 +6,7 @@ import ( "net/http" "strings" "sync" + "time" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -75,6 +76,26 @@ func (a *S3Action) Handle(w http.ResponseWriter, r *http.Request, next http.Hand return } + if ims := r.Header.Get("if-modified-since"); ims != "" { + imsTime, err := time.Parse(http.TimeFormat, ims) + if err == nil && (imsTime.Equal(stat.LastModified) || imsTime.After(stat.LastModified)) { + w.WriteHeader(http.StatusNotModified) + return + } + } + w.Header().Set("last-modified", stat.LastModified.Format(http.TimeFormat)) + + if stat.ChecksumSHA1 != "" { + if inm := r.Header.Get("if-none-match"); inm != "" { + if inm == stat.ChecksumSHA1 { + w.WriteHeader(http.StatusNotModified) + return + } + } + + w.Header().Set("ETag", stat.ChecksumSHA1) + } + var seek int64 var size = stat.Size if rh != nil { -- 2.50.1