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

Function copyImageResponse

httpserver/image_handlers.go:209–234  ·  view source on GitHub ↗
(
	w http.ResponseWriter,
	reader io.Reader,
	imageResponseCache *imageResponseCache,
	cacheKey string,
	contentType string,
	etag string,
	xImgddSI string,
)

Source from the content-addressed store, hash-verified

207}
208
209func copyImageResponse(
210 w http.ResponseWriter,
211 reader io.Reader,
212 imageResponseCache *imageResponseCache,
213 cacheKey string,
214 contentType string,
215 etag string,
216 xImgddSI string,
217) {
218 if imageResponseCache == nil {
219 io.Copy(w, reader)
220 return
221 }
222 body, err := io.ReadAll(io.LimitReader(reader, imageResponseCache.maxFileBytes+1))
223 if err != nil {
224 httpLogger.Info().Err(err).Msg("Unable to read image")
225 return
226 }
227 if int64(len(body)) > imageResponseCache.maxFileBytes {
228 w.Write(body)
229 io.Copy(w, reader)
230 return
231 }
232 imageResponseCache.put(cacheKey, contentType, etag, xImgddSI, body)
233 w.Write(body)
234}
235
236func sortStoredImages(storedImages []*domainmodels.StoredImage, storageDefRepo storage.StorageDefRepo) ([]storedImageWithStorageDef, error) {
237 var storedImageWithStorageDefs []storedImageWithStorageDef

Callers 2

makeImageHandlerFunction · 0.85
makeDirectImageHandlerFunction · 0.85

Calls 1

putMethod · 0.80

Tested by

no test coverage detected