From e46af034df63fdae63ca05e845118b5d91216fb3 Mon Sep 17 00:00:00 2001 From: johncming Date: Mon, 11 Mar 2019 21:45:25 +0800 Subject: [PATCH] bugfix: adjust or add close request body. affected modules: - lease/leasehttp - contrib/raftexample --- contrib/raftexample/httpapi.go | 1 + lease/leasehttp/http.go | 1 + 2 files changed, 2 insertions(+) diff --git a/contrib/raftexample/httpapi.go b/contrib/raftexample/httpapi.go index 86d27d397..75f5d616f 100644 --- a/contrib/raftexample/httpapi.go +++ b/contrib/raftexample/httpapi.go @@ -31,6 +31,7 @@ type httpKVAPI struct { func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { key := r.RequestURI + defer r.Body.Close() switch { case r.Method == "PUT": v, err := ioutil.ReadAll(r.Body) diff --git a/lease/leasehttp/http.go b/lease/leasehttp/http.go index 0f9c0c865..67e916dba 100644 --- a/lease/leasehttp/http.go +++ b/lease/leasehttp/http.go @@ -52,6 +52,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + defer r.Body.Close() b, err := ioutil.ReadAll(r.Body) if err != nil { http.Error(w, "error reading body", http.StatusBadRequest)