diff --git a/backends/gcs/get.go b/backends/gcs/get.go index 1c5e12e..83990fb 100644 --- a/backends/gcs/get.go +++ b/backends/gcs/get.go @@ -61,6 +61,7 @@ func ReadWithCache(ctx context.Context, response http.ResponseWriter, objectHandle := gcs.Bucket(bucket).Object(objectName) // get static-serving metadata and set headers err := setHeaders(ctx, objectHandle, response) + if err != nil { if err == storage.ErrObjectNotExist { http.Error(response, "", http.StatusNotFound) @@ -70,6 +71,17 @@ func ReadWithCache(ctx context.Context, response http.ResponseWriter, } } + // handle Etag + ifNoneMatchHeaders, ifNoneMatchHeaderPresent := request.Header[http.CanonicalHeaderKey("if-none-match")] + if ifNoneMatchHeaderPresent { + for _, etag := range ifNoneMatchHeaders { + if etag == response.Header().Get("Etag") { + response.WriteHeader(http.StatusNotModified) + return + } + } + } + // try the media cache var media io.Reader var pipeline filter.Pipeline diff --git a/backends/gcs/headers.go b/backends/gcs/headers.go index 14495e4..2300daf 100644 --- a/backends/gcs/headers.go +++ b/backends/gcs/headers.go @@ -55,6 +55,9 @@ func setHeaders(ctx context.Context, objectHandle *storage.ObjectHandle, if objectAttrs.ContentType != "" { response.Header().Set("Content-Type", objectAttrs.ContentType) } + if objectAttrs.Etag != "" { + response.Header().Set("Etag", objectAttrs.Etag) + } response.Header().Set("Content-Length", fmt.Sprint(objectAttrs.Size)) return }