Skip to content

Commit c36ca91

Browse files
iQQBotroboquat
authored andcommitted
[blobserve] handle warm-up request, add cache policy
1 parent 0f92a1f commit c36ca91

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

components/blobserve/pkg/blobserve/blobserve.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,27 @@ func (reg *Server) serve(w http.ResponseWriter, req *http.Request) {
224224
return
225225
}
226226

227+
// warm-up, didn't need response content
228+
if req.Method == http.MethodHead {
229+
w.Header().Set("Cache-Control", "no-cache")
230+
w.WriteHeader(http.StatusOK)
231+
return
232+
}
233+
227234
log.WithField("path", req.URL.Path).Debug("handling blobserve")
228235
pathPrefix := fmt.Sprintf("/%s", ref)
229236
if req.URL.Path == pathPrefix {
230237
req.URL.Path += "/"
231238
}
232239

233240
w.Header().Set("ETag", hash)
234-
w.Header().Set("Cache-Control", "no-cache")
241+
242+
inlineVarsValue := req.Header.Get("X-BlobServe-InlineVars")
243+
if inlineVarsValue == "" {
244+
w.Header().Set("Cache-Control", "public, max-age=31536000")
245+
} else {
246+
w.Header().Set("Cache-Control", "no-cache")
247+
}
235248

236249
// http.FileServer has a special case where ServeFile redirects any request where r.URL.Path
237250
// ends in "/index.html" to the same path, without the final "index.html".

0 commit comments

Comments
 (0)