MCPcopy Create free account
hub / github.com/blobcache/blobcache / handleRequest

Function handleRequest

src/bchttp/server.go:397–420  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, fn func(context.Context, Req) (*Resp, error))

Source from the content-addressed store, hash-verified

395}
396
397func handleRequest[Req, Resp any](w http.ResponseWriter, r *http.Request, fn func(context.Context, Req) (*Resp, error)) {
398 var req Req
399 if r.Method != "GET" {
400 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
401 http.Error(w, err.Error(), http.StatusBadRequest)
402 return
403 }
404 }
405 resp, err := fn(r.Context(), req)
406 if err != nil {
407 http.Error(w, err.Error(), http.StatusInternalServerError)
408 return
409 }
410 respData, err := json.Marshal(resp)
411 if err != nil {
412 http.Error(w, err.Error(), http.StatusInternalServerError)
413 return
414 }
415 w.Header().Set("Content-Type", "application/json")
416 w.WriteHeader(http.StatusOK)
417 if _, err := w.Write(respData); err != nil {
418 logctx.Warn(r.Context(), "writing http response", zap.Error(err))
419 }
420}
421
422func getSaltFromRequest(r *http.Request) (*blobcache.CID, error) {
423 saltStr := r.Header.Get("X-Salt")

Callers 4

ServeHTTPMethod · 0.85
handleVolumeMethod · 0.85
handleTxMethod · 0.85
handleQueueMethod · 0.85

Calls 5

HeaderMethod · 0.80
MarshalMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected