Skip to content

Commit

Permalink
fixes 403 on cached fetch to index file (#56) (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaecktec authored May 31, 2023
1 parent ab7902b commit 66596f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions s3proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions s3proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 66596f0

Please sign in to comment.