diff --git a/pkg/server/root.go b/pkg/server/root.go index a1d7fa51c..80cee8bc2 100644 --- a/pkg/server/root.go +++ b/pkg/server/root.go @@ -51,9 +51,17 @@ func newRootFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handle return root, nil } -func (rh *RootHandler) ServeHTTP(conn http.ResponseWriter, req *http.Request) { - if rh.ui != nil && camliMode(req) == "config" && auth.IsAuthorized(req) { - rh.ui.serveDiscovery(conn, req) +func (rh *RootHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { + // TODO(bradfitz): discovery should work without a 'ui' handler registered. + // It should be part of the root handler, not part of the UI handler. + if rh.ui != nil && wantsDiscovery(req) { + if auth.IsAuthorized(req) { + rh.ui.serveDiscovery(rw, req) + return + } + if !rh.Stealth { + http.Error(rw, "Unauthorized", http.StatusUnauthorized) + } return } @@ -65,8 +73,7 @@ func (rh *RootHandler) ServeHTTP(conn http.ResponseWriter, req *http.Request) { if auth.LocalhostAuthorized(req) { configLink = "

If you're coming from localhost, hit /setup.

" } - fmt.Fprintf(conn, - "This is camlistored, a "+ - "Camlistore server."+ - "%s\n", configLink) + fmt.Fprintf(rw, "This is camlistored, a "+ + "Camlistore server."+ + "%s\n", configLink) }