MCPcopy
hub / github.com/perkeep/perkeep / serveHTTP

Method serveHTTP

pkg/server/share.go:279–306  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

277}
278
279func (h *shareHandler) serveHTTP(rw http.ResponseWriter, req *http.Request) error {
280 var err error
281 pathSuffix := httputil.PathSuffix(req)
282 if len(pathSuffix) == 0 {
283 // This happens during testing because we don't go through PrefixHandler
284 pathSuffix = strings.TrimLeft(req.URL.Path, "/")
285 }
286 pathParts := strings.SplitN(pathSuffix, "/", 2)
287 blobRef, ok := blob.Parse(pathParts[0])
288 if !ok {
289 err = &shareError{code: invalidURL, response: badRequest,
290 message: fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix)}
291 } else {
292 err = h.handleGetViaSharing(rw, req, blobRef)
293 }
294 if se, ok := err.(*shareError); ok {
295 switch se.response {
296 case badRequest:
297 httputil.BadRequestError(rw, "%s", err)
298 case unauthorizedRequest:
299 if h.log {
300 log.Print(err)
301 }
302 auth.SendUnauthorized(rw, req)
303 }
304 }
305 return err
306}
307
308func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
309 h.serveHTTP(rw, req)

Callers 2

ServeHTTPMethod · 0.95
getMethod · 0.45

Calls 5

handleGetViaSharingMethod · 0.95
PathSuffixFunction · 0.92
ParseFunction · 0.92
BadRequestErrorFunction · 0.92
SendUnauthorizedFunction · 0.92

Tested by 1

getMethod · 0.36