Files
kopia/internal/server/api_object_get.go
Jarek Kowalski be4b897579 Support for remote repository (#427)
Support for remote content repository where all contents and
manifests are fetched over HTTP(S) instead of locally
manipulating blob storage

* server: implement content and manifest access APIs
* apiclient: moved Kopia API client to separate package
* content: exposed content.ValidatePrefix()
* manifest: added JSON serialization attributes to EntryMetadata
* repo: changed repo.Open() to return Repository instead of *DirectRepository
* repo: added apiServerRepository
* cli: added 'kopia repository connect server'
  This sets up repository connection via the API server instead of
  directly-manipulated storage.
* server: add support for specifying a list of usernames/password via --htpasswd-file
* tests: added API server repository E2E test
* server: only return manifests (policies and snapshots) belonging to authenticated user
2020-05-02 21:41:49 -07:00

47 lines
984 B
Go

package server
import (
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/kopia/kopia/repo/object"
)
func (s *Server) handleObjectGet(w http.ResponseWriter, r *http.Request) {
oidstr := mux.Vars(r)["objectID"]
oid, err := object.ParseID(oidstr)
if err != nil {
http.Error(w, "invalid object id", http.StatusBadRequest)
return
}
obj, err := s.rep.OpenObject(r.Context(), oid)
if err == object.ErrObjectNotFound {
http.Error(w, "object not found", http.StatusNotFound)
return
}
if cid, _, ok := oid.ContentID(); ok && cid.Prefix() == "k" {
w.Header().Set("Content-Type", "application/json")
}
fname := oid.String()
if p := r.URL.Query().Get("fname"); p != "" {
fname = p
w.Header().Set("Content-Disposition", "attachment; filename=\""+p+"\"")
}
mtime := time.Now()
if p := r.URL.Query().Get("mtime"); p != "" {
if m, err := time.Parse(time.RFC3339Nano, p); err == nil {
mtime = m
}
}
http.ServeContent(w, r, fname, mtime, obj)
}