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

Method ServeHTTP

src/bchttp/server.go:23–106  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

21}
22
23func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
24 switch {
25 case r.URL.Path == "/OpenFrom":
26 handleRequest(w, r, func(ctx context.Context, req OpenFromReq) (*OpenFromResp, error) {
27 handle, err := s.Service.OpenFrom(ctx, req.Base, req.Token, req.Mask)
28 if err != nil {
29 return nil, err
30 }
31 volInfo, err := s.Service.InspectVolume(ctx, *handle)
32 if err != nil {
33 return nil, err
34 }
35 return &OpenFromResp{Handle: *handle, Info: *volInfo}, nil
36 })
37 case r.URL.Path == "/OpenFiat":
38 handleRequest(w, r, func(ctx context.Context, req OpenFiatReq) (*OpenFiatResp, error) {
39 handle, err := s.Service.OpenFiat(ctx, req.Target, req.Mask)
40 if err != nil {
41 return nil, err
42 }
43 volInfo, err := s.Service.InspectVolume(ctx, *handle)
44 if err != nil {
45 return nil, err
46 }
47 return &OpenFiatResp{Handle: *handle, Info: *volInfo}, nil
48 })
49 case r.URL.Path == "/Endpoint":
50 handleRequest(w, r, func(ctx context.Context, req EndpointReq) (*EndpointResp, error) {
51 ep, err := s.Service.Endpoint(ctx)
52 if err != nil {
53 return nil, err
54 }
55 return &EndpointResp{Endpoint: ep}, nil
56 })
57 case r.URL.Path == "/KeepAlive":
58 handleRequest(w, r, func(ctx context.Context, req KeepAliveReq) (*KeepAliveResp, error) {
59 err := s.Service.KeepAlive(ctx, req.Handles)
60 if err != nil {
61 return nil, err
62 }
63 return &KeepAliveResp{}, nil
64 })
65 case r.URL.Path == "/Drop":
66 handleRequest(w, r, func(ctx context.Context, req DropReq) (*DropResp, error) {
67 err := s.Service.Drop(ctx, req.Handle)
68 if err != nil {
69 return nil, err
70 }
71 return &DropResp{}, nil
72 })
73 case r.URL.Path == "/ShareOut":
74 handleRequest(w, r, func(ctx context.Context, req ShareOutReq) (*ShareOutResp, error) {
75 handle, err := s.Service.ShareOut(ctx, req.Handle, req.Peer, req.Mask)
76 if err != nil {
77 return nil, err
78 }
79 return &ShareOutResp{Handle: *handle}, nil
80 })

Callers

nothing calls this directly

Calls 13

handleQueueMethod · 0.95
handleVolumeMethod · 0.95
handleTxMethod · 0.95
handleRequestFunction · 0.85
OpenFromMethod · 0.65
InspectVolumeMethod · 0.65
OpenFiatMethod · 0.65
EndpointMethod · 0.65
KeepAliveMethod · 0.65
DropMethod · 0.65
ShareOutMethod · 0.65
ShareInMethod · 0.65

Tested by

no test coverage detected