2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 19:38:57 +00:00

restic-server: Fix content length for HEAD requests

This commit is contained in:
Fabian Wickborn 2016-02-21 21:40:06 +01:00
parent 51d86370a5
commit 4749e610af

View File

@ -4,6 +4,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
@ -40,10 +41,12 @@ func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
func CheckConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
config := filepath.Join(c.path, "config")
if _, err := os.Stat(config); err != nil {
st, err := os.Stat(config)
if err != nil {
http.Error(w, "404 not found", 404)
return
}
w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
}
}
@ -113,11 +116,12 @@ func CheckBlob(c *Context) http.HandlerFunc {
dir := vars[1]
name := vars[2]
path := filepath.Join(c.path, dir, name)
_, err := os.Stat(path)
st, err := os.Stat(path)
if err != nil {
http.Error(w, "404 not found", 404)
return
}
w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
}
}