MCPcopy
hub / github.com/kopia/kopia / handleObjectGet

Function handleObjectGet

internal/server/api_object_get.go:14–53  ·  view source on GitHub ↗
(ctx context.Context, rc requestContext)

Source from the content-addressed store, hash-verified

12)
13
14func handleObjectGet(ctx context.Context, rc requestContext) {
15 oidstr := rc.muxVar("objectID")
16
17 if !requireUIUser(ctx, rc) {
18 http.Error(rc.w, "access denied", http.StatusForbidden)
19 return
20 }
21
22 oid, err := object.ParseID(oidstr)
23 if err != nil {
24 http.Error(rc.w, "invalid object id", http.StatusBadRequest)
25 return
26 }
27
28 obj, err := rc.rep.OpenObject(ctx, oid)
29 if errors.Is(err, object.ErrObjectNotFound) {
30 http.Error(rc.w, "object not found", http.StatusNotFound)
31 return
32 }
33
34 if snapshotfs.IsDirectoryID(oid) {
35 rc.w.Header().Set("Content-Type", "application/json")
36 }
37
38 fname := oid.String()
39 if p := rc.queryParam("fname"); p != "" {
40 fname = p
41 rc.w.Header().Set("Content-Disposition", "attachment; filename=\""+p+"\"")
42 }
43
44 mtime := clock.Now()
45
46 if p := rc.queryParam("mtime"); p != "" {
47 if m, err := time.Parse(time.RFC3339Nano, p); err == nil {
48 mtime = m
49 }
50 }
51
52 http.ServeContent(rc.w, rc.req, fname, mtime, obj)
53}

Callers

nothing calls this directly

Calls 10

ParseIDFunction · 0.92
IsDirectoryIDFunction · 0.92
NowFunction · 0.92
requireUIUserFunction · 0.85
muxVarMethod · 0.80
queryParamMethod · 0.80
ParseMethod · 0.80
ErrorMethod · 0.65
OpenObjectMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected