Make UI discovery have absolute paths, so root discovery using UI's discovery handler works.

Change-Id: Ieb1b5d143c528b4b15875aa810038c3ebdf30251
This commit is contained in:
Brad Fitzpatrick 2012-05-13 13:02:20 -07:00
parent a63556640d
commit 50fe7a2fda
3 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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,
})
}

View File

@ -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