Skip to content

Commit 9d73af6

Browse files
committed
Head requests are no longer redirect
1 parent 27f7c6e commit 9d73af6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

crproxy.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"net/textproto"
1212
"net/url"
13+
"strconv"
1314
"strings"
1415
"sync"
1516
"time"
@@ -677,7 +678,19 @@ func (c *CRProxy) notFoundResponse(rw http.ResponseWriter, r *http.Request) {
677678
http.NotFound(rw, r)
678679
}
679680

680-
func (c *CRProxy) redirect(rw http.ResponseWriter, r *http.Request, blobPath string) error {
681+
func (c *CRProxy) redirectBlob(rw http.ResponseWriter, r *http.Request, blobPath string) error {
682+
if r.Method == http.MethodHead {
683+
file, err := c.storageDriver.Stat(r.Context(), blobPath)
684+
if err != nil {
685+
return err
686+
}
687+
688+
rw.Header().Set("Content-Length", strconv.FormatInt(file.Size(), 10))
689+
rw.Header().Set("Last-Modified", file.ModTime().UTC().Format(http.TimeFormat))
690+
rw.WriteHeader(http.StatusOK)
691+
return nil
692+
}
693+
681694
options := map[string]interface{}{
682695
"method": r.Method,
683696
}

crproxy_blob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c *CRProxy) cacheBlobResponse(rw http.ResponseWriter, r *http.Request, inf
6868
}
6969
}
7070

71-
err = c.redirect(rw, r, blobPath)
71+
err = c.redirectBlob(rw, r, blobPath)
7272
if err == nil {
7373
return
7474
}
@@ -120,7 +120,7 @@ func (c *CRProxy) cacheBlobResponse(rw http.ResponseWriter, r *http.Request, inf
120120
}
121121
}
122122

123-
err = c.redirect(rw, r, blobPath)
123+
err = c.redirectBlob(rw, r, blobPath)
124124
if err != nil {
125125
if c.logger != nil {
126126
c.logger.Println("failed to redirect", blobPath, err)

0 commit comments

Comments
 (0)