From 544d90184021091eed83cf6a5e4f007e70dc0e3e Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Thu, 19 Sep 2013 00:13:23 -0700 Subject: [PATCH] Add support for downloading an assembled blob via the share URL. Bug: https://code.google.com/p/camlistore/issues/detail?id=220 Change-Id: I4604105d2679010d6f546692abbce0d57bae2983 --- pkg/server/share.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/server/share.go b/pkg/server/share.go index 82d903acb..44fe9eac6 100644 --- a/pkg/server/share.go +++ b/pkg/server/share.go @@ -24,6 +24,7 @@ import ( "io/ioutil" "log" "net/http" + "strconv" "strings" "time" @@ -54,6 +55,9 @@ func newShareFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handl if blobRoot == "" { return nil, errors.New("No blobRoot defined for share handler") } + if err = conf.Validate(); err != nil { + return + } share := &shareHandler{ blobRoot: blobRoot, @@ -171,13 +175,23 @@ func handleGetViaSharing(conn http.ResponseWriter, req *http.Request, viaPathOkay = true - gethandler.ServeBlobRef(conn, req, blobRef, fetcher) + if assemble, _ := strconv.ParseBool(req.FormValue("assemble")); assemble { + dh := &DownloadHandler{ + Fetcher: fetcher, + // TODO(aa): It would be nice to specify a local cache here, as the UI handler does. + } + dh.ServeHTTP(conn, req, blobRef) + } else { + gethandler.ServeBlobRef(conn, req, blobRef, fetcher) + } } func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - blobRef, ok := blob.Parse(httputil.PathSuffix(req)) + pathSuffix := httputil.PathSuffix(req) + pathParts := strings.SplitN(pathSuffix, "/", 2) + blobRef, ok := blob.Parse(pathParts[0]) if !ok { - http.Error(rw, "Malformed share URL.", 400) + http.Error(rw, fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix), 400) return } handleGetViaSharing(rw, req, blobRef, h.fetcher)