Read request body before sending response

This commit is contained in:
Richard van der Hoff 2018-03-06 10:23:24 +00:00
parent 00b9337e01
commit e88a448a20

View file

@ -85,8 +85,9 @@ type submitResponse struct {
func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// if we attempt to return a response without reading the request body, // if we attempt to return a response without reading the request body,
// haproxy gets upset and returns a 500. Let's try this. // haproxy (apache?) gets upset and returns a 500. Let's try this.
defer req.Body.Close() defer req.Body.Close()
defer io.Copy(ioutil.Discard, req.Body)
if req.Method != "POST" && req.Method != "OPTIONS" { if req.Method != "POST" && req.Method != "OPTIONS" {
respond(405, w) respond(405, w)
@ -150,7 +151,7 @@ func parseRequest(w http.ResponseWriter, req *http.Request, reportDir string) *p
} }
if length > maxPayloadSize { if length > maxPayloadSize {
log.Println("Content-length", length, "too large") log.Println("Content-length", length, "too large")
http.Error(w, fmt.Sprintf("Content too large (max %i)", maxPayloadSize), 413) http.Error(w, fmt.Sprintf("Content too large (max %d)", maxPayloadSize), 413)
return nil return nil
} }