swarm/api/http: reject requests without content-length

This commit is contained in:
Felix Lange 2016-11-10 21:14:17 +01:00
parent 23420ff67a
commit 5cd4430a8d

View File

@ -115,7 +115,11 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
switch { switch {
case r.Method == "POST" || r.Method == "PUT": case r.Method == "POST" || r.Method == "PUT":
key, err := a.Store(r.Body, r.ContentLength, nil) if r.Header.Get("content-length") == "" {
http.Error(w, "Missing Content-Length header in request.", http.StatusBadRequest)
return
}
key, err := a.Store(io.LimitReader(r.Body, r.ContentLength), r.ContentLength, nil)
if err == nil { if err == nil {
glog.V(logger.Debug).Infof("Content for %v stored", key.Log()) glog.V(logger.Debug).Infof("Content for %v stored", key.Log())
} else { } else {