Browse Source

Merge pull request #10534 from johncming/close_reader

 close http request body after read it.
Xiang Li 6 years ago
parent
commit
dc50416157
2 changed files with 2 additions and 0 deletions
  1. 1 0
      contrib/raftexample/httpapi.go
  2. 1 0
      lease/leasehttp/http.go

+ 1 - 0
contrib/raftexample/httpapi.go

@@ -31,6 +31,7 @@ type httpKVAPI struct {
 
 
 func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	key := r.RequestURI
 	key := r.RequestURI
+	defer r.Body.Close()
 	switch {
 	switch {
 	case r.Method == "PUT":
 	case r.Method == "PUT":
 		v, err := ioutil.ReadAll(r.Body)
 		v, err := ioutil.ReadAll(r.Body)

+ 1 - 0
lease/leasehttp/http.go

@@ -52,6 +52,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
+	defer r.Body.Close()
 	b, err := ioutil.ReadAll(r.Body)
 	b, err := ioutil.ReadAll(r.Body)
 	if err != nil {
 	if err != nil {
 		http.Error(w, "error reading body", http.StatusBadRequest)
 		http.Error(w, "error reading body", http.StatusBadRequest)