tLimit writing to Content-Length header - partage - File upload system
(HTM) git clone git://git.z3bra.org/partage.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7aeb9213cb2bfabf83cc2c04e4d3acd172134c55
(DIR) parent 847a32b6a4b1d4d6ca25a5c70a48ca1435607992
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Mon, 11 Oct 2021 17:14:13 +0200
Limit writing to Content-Length header
Diffstat:
M partage.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/partage.go b/partage.go
t@@ -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)
t@@ -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
}
t@@ -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
}