Limit incoming request body size for all endpoints and add rate limiting wrappera round storage

This commit is contained in:
breel
2020-07-26 20:25:39 -06:00
parent c3b948556c
commit 36c4ae520d
6 changed files with 86 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ func filesPostFromDirectLink(w http.ResponseWriter, r *http.Request) error {
return err
}
defer f.Close()
_, err = io.Copy(f, io.LimitReader(resp.Body, config.New().MaxFileSize))
_, err = io.Copy(f, resp.Body)
return err
}
@@ -109,7 +109,7 @@ func filesPostFromUpload(w http.ResponseWriter, r *http.Request) error {
return err
}
defer file.Close()
if _, err := io.Copy(f, io.LimitReader(file, config.New().MaxFileSize)); err != nil {
if _, err := io.Copy(f, file); err != nil {
return err
}
return json.NewEncoder(w).Encode(map[string]interface{}{"status": "ok"})

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"local/dndex/config"
"local/dndex/storage"
"local/gziphttp"
@@ -72,6 +73,13 @@ func jsonHandler(g storage.Graph) http.Handler {
defer gz.Close()
w = gz
}
r.Body = struct {
io.Reader
io.Closer
}{
Reader: io.LimitReader(r.Body, config.New().MaxFileSize),
Closer: r.Body,
}
mux.ServeHTTP(w, r)
})
}