From 50fe7a2fda092dc3a863f4173d981c7adbe17f86 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 13 May 2012 13:02:20 -0700 Subject: [PATCH] Make UI discovery have absolute paths, so root discovery using UI's discovery handler works. Change-Id: Ieb1b5d143c528b4b15875aa810038c3ebdf30251 --- pkg/blobserver/registry.go | 3 +++ pkg/server/ui.go | 9 ++++++--- pkg/serverconfig/serverconfig.go | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/blobserver/registry.go b/pkg/blobserver/registry.go index e5b472736..c1038fa1b 100644 --- a/pkg/blobserver/registry.go +++ b/pkg/blobserver/registry.go @@ -28,6 +28,9 @@ import ( var ErrHandlerTypeNotFound = errors.New("requested handler type not loaded") type Loader interface { + // MyPrefix returns the prefix of the handler currently being constructed. + MyPrefix() string + GetStorage(prefix string) (Storage, error) GetHandlerType(prefix string) string // returns "" if unknown diff --git a/pkg/server/ui.go b/pkg/server/ui.go index ca84b71fb..52518d8b1 100644 --- a/pkg/server/ui.go +++ b/pkg/server/ui.go @@ -21,6 +21,7 @@ import ( "fmt" "log" "net/http" + "path" "regexp" "strconv" "strings" @@ -61,6 +62,7 @@ type UIHandler struct { PublishRoots map[string]*PublishHandler + prefix string // of the UI handler itself Storage blobserver.Storage // of BlobRoot Cache blobserver.Storage // or nil Search *search.Handler // or nil @@ -75,6 +77,7 @@ func init() { func newUIFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err error) { ui := &UIHandler{ + prefix: ld.MyPrefix(), BlobRoot: conf.OptionalString("blobRoot", ""), SearchRoot: conf.OptionalString("searchRoot", ""), JSONSignRoot: conf.OptionalString("jsonSignRoot", ""), @@ -257,9 +260,9 @@ func (ui *UIHandler) serveDiscovery(rw http.ResponseWriter, req *http.Request) { "blobRoot": ui.BlobRoot, "searchRoot": ui.SearchRoot, "jsonSignRoot": ui.JSONSignRoot, - "uploadHelper": "?camli.mode=uploadhelper", // hack; remove with better javascript - "downloadHelper": "./download/", - "directoryHelper": "./tree/", + "uploadHelper": ui.prefix + "?camli.mode=uploadhelper", // hack; remove with better javascript + "downloadHelper": path.Join(ui.prefix, "download") + "/", + "directoryHelper": path.Join(ui.prefix, "tree") + "/", "publishRoots": pubRoots, }) } diff --git a/pkg/serverconfig/serverconfig.go b/pkg/serverconfig/serverconfig.go index 9f7c441d9..c7210831e 100644 --- a/pkg/serverconfig/serverconfig.go +++ b/pkg/serverconfig/serverconfig.go @@ -50,6 +50,7 @@ type handlerLoader struct { baseURL string config map[string]*handlerConfig // prefix -> config handler map[string]interface{} // prefix -> http.Handler / func / blobserver.Storage + curPrefix string // optional context (for App Engine, the first request that // started up the process). we may need this if setting up @@ -186,6 +187,10 @@ func (hl *handlerLoader) getOrSetup(prefix string) interface{} { return hl.handler[prefix] } +func (hl *handlerLoader) MyPrefix() string { + return hl.curPrefix +} + func (hl *handlerLoader) GetStorage(prefix string) (blobserver.Storage, error) { hl.setupHandler(prefix) if s, ok := hl.handler[prefix].(blobserver.Storage); ok { @@ -243,6 +248,8 @@ func (hl *handlerLoader) setupHandler(prefix string) { } }() + hl.curPrefix = prefix + if strings.HasPrefix(h.htype, "storage-") { stype := h.htype[len("storage-"):] // Assume a storage interface