Limit writing to Content-Length header
git-svn-id: file:///srv/svn/repo/marisa/trunk@5 d6811dac-2434-b64a-9ddc-f563ab233461
This commit is contained in:
@@ -32,7 +32,7 @@ func contenttype(f *os.File) string {
|
|||||||
return mime
|
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)
|
buffer := make([]byte, 4096)
|
||||||
eof := false
|
eof := false
|
||||||
sz := int64(0)
|
sz := int64(0)
|
||||||
@@ -50,8 +50,8 @@ func writefile(f *os.File, s io.ReadCloser) int64 {
|
|||||||
|
|
||||||
/* ensure we don't write more than expected */
|
/* ensure we don't write more than expected */
|
||||||
r := int64(n)
|
r := int64(n)
|
||||||
if sz+r > conf.maxsize {
|
if sz+r > contentlength {
|
||||||
r = conf.maxsize - sz
|
r = contentlength - sz
|
||||||
eof = true
|
eof = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ func parse(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if writefile(f, r.Body) < 0 {
|
if writefile(f, r.Body, r.ContentLength) < 0 {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user