5748: Write index data to http.ResponseWriter, instead of using string
[arvados.git] / services / keepstore / handlers.go
index f462b0aae147605bc502e9fe49f69cd2dfc8f0ed..6492045c68b1f0cbd9de2e00aaa0859ce6ec8b9a 100644 (file)
@@ -160,6 +160,11 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
        // the body: avoid transmitting data that will not end up
        // being written anyway.
 
+       if req.ContentLength == -1 {
+               http.Error(resp, SizeRequiredError.Error(), SizeRequiredError.HTTPCode)
+               return
+       }
+
        if req.ContentLength > BLOCKSIZE {
                http.Error(resp, TooLongError.Error(), TooLongError.HTTPCode)
                return
@@ -192,7 +197,7 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
        return_hash := fmt.Sprintf("%s+%d", hash, len(buf))
        api_token := GetApiToken(req)
        if PermissionSecret != nil && api_token != "" {
-               expiry := time.Now().Add(permission_ttl)
+               expiry := time.Now().Add(blob_signature_ttl)
                return_hash = SignLocator(return_hash, api_token, expiry)
        }
        resp.Write([]byte(return_hash + "\n"))
@@ -210,11 +215,18 @@ func IndexHandler(resp http.ResponseWriter, req *http.Request) {
 
        prefix := mux.Vars(req)["prefix"]
 
-       var index string
        for _, vol := range KeepVM.AllReadable() {
-               index = index + vol.Index(prefix)
+               if err := vol.IndexTo(prefix, resp); err != nil {
+                       // The only errors returned by IndexTo are
+                       // write errors returned by resp.Write(),
+                       // which probably means the client has
+                       // disconnected and this error will never be
+                       // reported to the client -- but it will
+                       // appear in our own error log.
+                       http.Error(resp, err.Error(), http.StatusInternalServerError)
+                       return
+               }
        }
-       resp.Write([]byte(index))
 }
 
 // StatusHandler