partage

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.z3bra.org/partage.git
Log | Files | Refs

commit 7aeb9213cb2bfabf83cc2c04e4d3acd172134c55
parent 847a32b6a4b1d4d6ca25a5c70a48ca1435607992
Author: Willy Goiffon <dev@z3bra.org>
Date:   Mon, 11 Oct 2021 17:14:13 +0200

Limit writing to Content-Length header

Diffstat:
Mpartage.go | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/partage.go b/partage.go @@ -32,7 +32,7 @@ func contenttype(f *os.File) string { return mime } -func writefile(f *os.File, s io.ReadCloser) int64 { +func writefile(f *os.File, s io.ReadCloser, contentlength int64) int64 { buffer := make([]byte, 4096) eof := false sz := int64(0) @@ -50,8 +50,8 @@ func writefile(f *os.File, s io.ReadCloser) int64 { /* ensure we don't write more than expected */ r := int64(n) - if sz+r > conf.maxsize { - r = conf.maxsize - sz + if sz+r > contentlength { + r = contentlength - sz eof = true } @@ -119,7 +119,7 @@ func parse(w http.ResponseWriter, r *http.Request) { } defer f.Close() - if writefile(f, r.Body) < 0 { + if writefile(f, r.Body, r.ContentLength) < 0 { w.WriteHeader(http.StatusInternalServerError) return }