MCPcopy Create free account
hub / github.com/ericls/imgdd / writeCachedImageResponse

Function writeCachedImageResponse

httpserver/image_response_cache.go:104–119  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, entry *imageResponseCacheEntry)

Source from the content-addressed store, hash-verified

102}
103
104func writeCachedImageResponse(w http.ResponseWriter, r *http.Request, entry *imageResponseCacheEntry) {
105 if r.Header.Get("If-None-Match") == entry.etag {
106 w.WriteHeader(http.StatusNotModified)
107 return
108 }
109 w.Header().Set("Content-Type", entry.contentType)
110 w.Header().Set("Content-Length", stringInt(len(entry.body)))
111 w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
112 w.Header().Set("ETag", entry.etag)
113 w.Header().Set("X-imgdd-si", entry.xImgddSI)
114 w.WriteHeader(http.StatusOK)
115 if r.Method == http.MethodHead {
116 return
117 }
118 w.Write(entry.body)
119}
120
121func stringInt(v int) string {
122 return strconv.Itoa(v)

Callers 2

makeImageHandlerFunction · 0.85
makeDirectImageHandlerFunction · 0.85

Calls 3

stringIntFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected