From 3d5c28511fe90d92ef056875e5ed6d3dc93c5a47 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 27 Apr 2018 13:27:56 -0700 Subject: [PATCH] Log instead of panicking in HTTP handler on GET to /index/ (no Fetcher) And change two Camlistore instances to Perkeep. Change-Id: Id515480ecdc0c997e1700204d63ef4cc6a8c8cc4 --- pkg/blobserver/gethandler/get.go | 7 +++++++ pkg/serverinit/serverinit.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/blobserver/gethandler/get.go b/pkg/blobserver/gethandler/get.go index e906665f4..78b956d31 100644 --- a/pkg/blobserver/gethandler/get.go +++ b/pkg/blobserver/gethandler/get.go @@ -20,6 +20,7 @@ package gethandler // import "perkeep.org/pkg/blobserver/gethandler" import ( "fmt" "io" + "log" "net/http" "os" "regexp" @@ -63,6 +64,12 @@ func (h *Handler) ServeHTTP(conn http.ResponseWriter, req *http.Request) { // ServeBlobRef serves a blob. func ServeBlobRef(rw http.ResponseWriter, req *http.Request, blobRef blob.Ref, fetcher blob.Fetcher) { ctx := req.Context() + if fetcher == nil { + log.Printf("gethandler: no fetcher configured for %s (ref=%v)", req.URL.Path, blobRef) + rw.WriteHeader(http.StatusNotFound) + fmt.Fprintf(rw, "no fetcher configured", blobRef) + return + } rc, size, err := fetcher.Fetch(ctx, blobRef) switch err { case nil: diff --git a/pkg/serverinit/serverinit.go b/pkg/serverinit/serverinit.go index d2a9fa37a..c0cfc393a 100644 --- a/pkg/serverinit/serverinit.go +++ b/pkg/serverinit/serverinit.go @@ -86,7 +86,7 @@ type handlerLoader struct { } // A HandlerInstaller is anything that can register an HTTP Handler at -// a prefix path. Both *http.ServeMux and camlistore.org/pkg/webserver.Server +// a prefix path. Both *http.ServeMux and perkeep.org/pkg/webserver.Server // implement HandlerInstaller. type HandlerInstaller interface { Handle(path string, h http.Handler) @@ -109,7 +109,7 @@ func parseCamliPath(path string) (action string, err error) { } func unsupportedHandler(conn http.ResponseWriter, req *http.Request) { - httputil.BadRequestError(conn, "Unsupported camlistore path or method.") + httputil.BadRequestError(conn, "Unsupported Perkeep path or method.") } func (s *storageAndConfig) Config() *blobserver.Config {