1
mirror of https://github.com/rclone/rclone synced 2024-12-27 19:43:48 +01:00

serve restic: only accept v2 API requests for list

This commit is contained in:
Nick Craig-Wood 2018-03-08 10:09:56 +00:00
parent 43c7ea81df
commit 4e90ad04d5

View File

@ -143,6 +143,10 @@ these **must** end with /. Eg
},
}
const (
resticAPIV2 = "application/vnd.x.restic.rest.v2"
)
// server contains everything to run the server
type server struct {
f fs.Fs
@ -362,6 +366,12 @@ func (ls *listItems) add(entry fs.DirEntry) {
func (s *server) listObjects(w http.ResponseWriter, r *http.Request, remote string) {
fs.Debugf(remote, "list request")
if r.Header.Get("Accept") != resticAPIV2 {
fs.Errorf(remote, "Restic v2 API required")
http.Error(w, "Restic v2 API required", http.StatusBadRequest)
return
}
// make sure an empty list is returned, and not a 'nil' value
ls := listItems{}