1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-26 09:47:49 +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 ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -40,10 +41,12 @@ func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
func CheckConfig(c *Context) http.HandlerFunc { func CheckConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
config := filepath.Join(c.path, "config") 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) http.Error(w, "404 not found", 404)
return return
} }
w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
} }
} }
@ -113,11 +116,12 @@ func CheckBlob(c *Context) http.HandlerFunc {
dir := vars[1] dir := vars[1]
name := vars[2] name := vars[2]
path := filepath.Join(c.path, dir, name) path := filepath.Join(c.path, dir, name)
_, err := os.Stat(path) st, err := os.Stat(path)
if err != nil { if err != nil {
http.Error(w, "404 not found", 404) http.Error(w, "404 not found", 404)
return return
} }
w.Header().Add("Content-Length", fmt.Sprint(st.Size()))
} }
} }