Add discovery handler on root.

Change-Id: If816ff0dd5bb57d52445aff8cc67b8c801b606a8
This commit is contained in:
Brad Fitzpatrick 2012-05-13 12:16:59 -07:00
parent de535fa264
commit 618efee2f5
1 changed files with 11 additions and 0 deletions

View File

@ -29,6 +29,8 @@ import (
type RootHandler struct {
// Don't advertise anything to non-authenticated clients.
Stealth bool
ui *UIHandler // or nil, if none configured
}
func init() {
@ -42,10 +44,19 @@ func newRootFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handle
return
}
if _, h, err := ld.FindHandlerByType("ui"); err == nil {
root.ui = h.(*UIHandler)
}
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)
return
}
if rh.Stealth {
return
}