MCPcopy
hub / github.com/grafana/dskit / downloadKey

Function downloadKey

kv/memberlist/http_status_handler.go:215–243  ·  view source on GitHub ↗
(w http.ResponseWriter, kv *KV, store map[string]ValueDesc, key string)

Source from the content-addressed store, hash-verified

213}
214
215func downloadKey(w http.ResponseWriter, kv *KV, store map[string]ValueDesc, key string) {
216 if store[key].value == nil {
217 http.Error(w, "value not found", http.StatusNotFound)
218 return
219 }
220
221 val := store[key]
222
223 c := kv.GetCodec(store[key].CodecID)
224 if c == nil {
225 http.Error(w, "codec not found", http.StatusNotFound)
226 return
227 }
228
229 encoded, err := c.Encode(val.value)
230 if err != nil {
231 http.Error(w, fmt.Sprintf("failed to encode: %v", err), http.StatusInternalServerError)
232 return
233 }
234
235 w.Header().Add("content-type", "application/octet-stream")
236 // Set content-length so that client knows whether it has received full response or not.
237 w.Header().Add("content-length", strconv.Itoa(len(encoded)))
238 w.Header().Add("content-disposition", fmt.Sprintf("attachment; filename=%d-%s", val.Version, key))
239 w.WriteHeader(200)
240
241 // Ignore errors, we cannot do anything about them.
242 _, _ = w.Write(encoded)
243}
244
245//go:embed status.gohtml
246var defaultPageContent string

Callers 1

ServeHTTPMethod · 0.85

Calls 7

EncodeMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45
GetCodecMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected