From 4749e610af7b5c8c9b0dfc8803579a8ee46d273c Mon Sep 17 00:00:00 2001 From: Fabian Wickborn Date: Sun, 21 Feb 2016 21:40:06 +0100 Subject: [PATCH] restic-server: Fix content length for HEAD requests --- src/restic/cmd/restic-server/handlers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/restic/cmd/restic-server/handlers.go b/src/restic/cmd/restic-server/handlers.go index cd2fd518b..6c87ef121 100644 --- a/src/restic/cmd/restic-server/handlers.go +++ b/src/restic/cmd/restic-server/handlers.go @@ -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())) } }