mirror of
https://github.com/restic/rest-server.git
synced 2026-09-12 15:16:16 -07:00
Implement amended API protocol v2
The version is now selected via the HTTP request header "Accept".
This commit is contained in:
committed by
Zlatko Čalušić
parent
cd4d054887
commit
bf34e9d62d
+21
@@ -254,11 +254,30 @@ func DeleteConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
mimeTypeAPIV1 = "application/vnd.x.restic.rest.v1"
|
||||||
|
mimeTypeAPIV2 = "application/vnd.x.restic.rest.v2"
|
||||||
|
)
|
||||||
|
|
||||||
// ListBlobs lists all blobs of a given type in an arbitrary order.
|
// ListBlobs lists all blobs of a given type in an arbitrary order.
|
||||||
func ListBlobs(w http.ResponseWriter, r *http.Request) {
|
func ListBlobs(w http.ResponseWriter, r *http.Request) {
|
||||||
if Config.Debug {
|
if Config.Debug {
|
||||||
log.Println("ListBlobs()")
|
log.Println("ListBlobs()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch r.Header.Get("Accept") {
|
||||||
|
case mimeTypeAPIV2:
|
||||||
|
ListBlobsV2(w, r)
|
||||||
|
default:
|
||||||
|
ListBlobsV1(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListBlobsV1 lists all blobs of a given type in an arbitrary order.
|
||||||
|
func ListBlobsV1(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if Config.Debug {
|
||||||
|
log.Println("ListBlobsV1()")
|
||||||
|
}
|
||||||
fileType := pat.Param(r, "type")
|
fileType := pat.Param(r, "type")
|
||||||
path, err := getPath(r, fileType)
|
path, err := getPath(r, fileType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -305,6 +324,7 @@ func ListBlobs(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", mimeTypeAPIV1)
|
||||||
_, _ = w.Write(data)
|
_, _ = w.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +385,7 @@ func ListBlobsV2(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", mimeTypeAPIV2)
|
||||||
_, _ = w.Write(data)
|
_, _ = w.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,6 @@ func NewMux() *goji.Mux {
|
|||||||
mux.HandleFunc(pat.Post("/:repo/config"), SaveConfig)
|
mux.HandleFunc(pat.Post("/:repo/config"), SaveConfig)
|
||||||
mux.HandleFunc(pat.Delete("/config"), DeleteConfig)
|
mux.HandleFunc(pat.Delete("/config"), DeleteConfig)
|
||||||
mux.HandleFunc(pat.Delete("/:repo/config"), DeleteConfig)
|
mux.HandleFunc(pat.Delete("/:repo/config"), DeleteConfig)
|
||||||
mux.HandleFunc(pat.Get("/v2/:type/"), ListBlobsV2)
|
|
||||||
mux.HandleFunc(pat.Get("/v2/:repo/:type/"), ListBlobsV2)
|
|
||||||
mux.HandleFunc(pat.Get("/:type/"), ListBlobs)
|
mux.HandleFunc(pat.Get("/:type/"), ListBlobs)
|
||||||
mux.HandleFunc(pat.Get("/:repo/:type/"), ListBlobs)
|
mux.HandleFunc(pat.Get("/:repo/:type/"), ListBlobs)
|
||||||
mux.HandleFunc(pat.Head("/:type/:name"), CheckBlob)
|
mux.HandleFunc(pat.Head("/:type/:name"), CheckBlob)
|
||||||
|
|||||||
Reference in New Issue
Block a user