Minor cleanup and fixes

- Do not allow '.' as path component, because it undermines depth
  checks, and add tests
- Fix GiB reporting
- Fix metrics label
- Helper function for http errors
This commit is contained in:
Konrad Wojas 2020-05-31 21:36:39 +08:00 committed by Alexander Neumann
parent 1f593fafaf
commit d4cd47e503
5 changed files with 41 additions and 18 deletions

6
mux.go
View file

@ -12,6 +12,10 @@ import (
"github.com/restic/rest-server/quota"
)
const (
GiB = 1024 * 1024 * 1024
)
func (s *Server) debugHandler(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
@ -58,7 +62,7 @@ func NewHandler(server *Server) (http.Handler, error) {
return nil, err
}
server.quotaManager = qm
log.Printf("Quota initialized, currenly using %.2f GiB", float64(qm.SpaceUsed()/1024/1024))
log.Printf("Quota initialized, currenly using %.2f GiB", float64(qm.SpaceUsed())/GiB)
}
mux := http.NewServeMux()