Make discory work with an Accept header on the root

This commit is contained in:
Brad Fitzpatrick 2012-11-07 18:04:40 +01:00
parent 316d3cff31
commit df5eee936d
1 changed files with 14 additions and 7 deletions

View File

@ -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 = "<p>If you're coming from localhost, hit <a href='/setup'>/setup</a>.</p>"
}
fmt.Fprintf(conn,
"<html><body>This is camlistored, a "+
"<a href='http://camlistore.org'>Camlistore</a> server."+
"%s</body></html>\n", configLink)
fmt.Fprintf(rw, "<html><body>This is camlistored, a "+
"<a href='http://camlistore.org'>Camlistore</a> server."+
"%s</body></html>\n", configLink)
}