MCPcopy
hub / github.com/google/go-containerregistry / handle

Method handle

pkg/registry/manifest.go:94–253  ·  view source on GitHub ↗

https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pulling-an-image-manifest https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pushing-an-image

(resp http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

92// https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pulling-an-image-manifest
93// https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pushing-an-image
94func (m *manifests) handle(resp http.ResponseWriter, req *http.Request) *regError {
95 elem := strings.Split(req.URL.Path, "/")
96 elem = elem[1:]
97 target := elem[len(elem)-1]
98 repo := strings.Join(elem[1:len(elem)-2], "/")
99
100 switch req.Method {
101 case http.MethodGet:
102 m.lock.RLock()
103 defer m.lock.RUnlock()
104
105 c, ok := m.manifests[repo]
106 if !ok {
107 return &regError{
108 Status: http.StatusNotFound,
109 Code: "NAME_UNKNOWN",
110 Message: "Unknown name",
111 }
112 }
113 m, ok := c[target]
114 if !ok {
115 return &regError{
116 Status: http.StatusNotFound,
117 Code: "MANIFEST_UNKNOWN",
118 Message: "Unknown manifest",
119 }
120 }
121
122 h, _, _ := v1.SHA256(bytes.NewReader(m.blob))
123 resp.Header().Set("Docker-Content-Digest", h.String())
124 resp.Header().Set("Content-Type", m.contentType)
125 resp.Header().Set("Content-Length", fmt.Sprint(len(m.blob)))
126 resp.WriteHeader(http.StatusOK)
127 io.Copy(resp, bytes.NewReader(m.blob))
128 return nil
129
130 case http.MethodHead:
131 m.lock.RLock()
132 defer m.lock.RUnlock()
133
134 if _, ok := m.manifests[repo]; !ok {
135 return &regError{
136 Status: http.StatusNotFound,
137 Code: "NAME_UNKNOWN",
138 Message: "Unknown name",
139 }
140 }
141 m, ok := m.manifests[repo][target]
142 if !ok {
143 return &regError{
144 Status: http.StatusNotFound,
145 Code: "MANIFEST_UNKNOWN",
146 Message: "Unknown manifest",
147 }
148 }
149
150 h, _, _ := v1.SHA256(bytes.NewReader(m.blob))
151 resp.Header().Set("Docker-Content-Digest", h.String())

Callers

nothing calls this directly

Calls 11

SHA256Function · 0.92
MediaTypeTypeAlias · 0.92
ParseIndexManifestFunction · 0.92
BytesMethod · 0.80
IsIndexMethod · 0.80
IsDistributableMethod · 0.80
IsImageMethod · 0.80
StringMethod · 0.65
GetMethod · 0.65
SetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected