From df5eee936d0031b7dc547a9f088a65ca8bcc988b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 7 Nov 2012 18:04:40 +0100 Subject: [PATCH] Make discory work with an Accept header on the root --- pkg/server/root.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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) }