From 66596f074b8c2b0dc3f29200de63d752cebb28f2 Mon Sep 17 00:00:00 2001 From: Constantin Date: Wed, 31 May 2023 19:35:48 +0200 Subject: [PATCH] fixes 403 on cached fetch to index file (#56) (#57) --- s3proxy.go | 5 +++-- s3proxy_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/s3proxy.go b/s3proxy.go index d3470b2..f939b13 100644 --- a/s3proxy.go +++ b/s3proxy.go @@ -446,7 +446,8 @@ func (p S3Proxy) GetHandler(w http.ResponseWriter, r *http.Request, fullPath str for _, indexPage := range p.IndexNames { indexPath := path.Join(fullPath, indexPage) obj, err = p.getS3Object(p.Bucket, indexPath, r.Header) - if err == nil { + caddyErr := convertToCaddyError(err) + if err == nil || caddyErr.StatusCode == 304 { // We found an index! isDir = false break @@ -487,7 +488,7 @@ func (p S3Proxy) GetHandler(w http.ResponseWriter, r *http.Request, fullPath str if err != nil { caddyErr := convertToCaddyError(err) if caddyErr.StatusCode == http.StatusNotFound { - // Log as debug as this one may be qute common + // Log as debug as this one may be quite common p.log.Debug("not found", zap.String("bucket", p.Bucket), zap.String("key", fullPath), diff --git a/s3proxy_test.go b/s3proxy_test.go index af9e886..4540a91 100644 --- a/s3proxy_test.go +++ b/s3proxy_test.go @@ -320,6 +320,17 @@ func TestProxy(t *testing.T) { expectedCode: http.StatusOK, expectedResponseText: "my index.html", }, + { + name: "returns 304 If-None-Match on index", + proxy: S3Proxy{Bucket: bucketName, IndexNames: []string{"index.html"}}, + method: http.MethodGet, + path: "/inner/", + headers: http.Header{ + "If-None-Match": []string{`"44bacca965de5aef310706cc55c4a7b0"`}, + }, + expectedCode: http.StatusNotModified, + expectsEmptyResponse: true, + }, { name: "cannot browse", proxy: S3Proxy{Bucket: bucketName},