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
This commit is contained in:
Aaron Boodman 2013-09-19 00:13:23 -07:00
parent f0a00be32b
commit 544d901840
1 changed files with 17 additions and 3 deletions

View File

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