From 63171417c1451c9d8d8770cea87057b657fc5a96 Mon Sep 17 00:00:00 2001 From: Evgeny Danilenko Date: Tue, 1 Mar 2016 19:10:15 +0300 Subject: [PATCH] Request body discard added --- rest/request.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rest/request.go b/rest/request.go index 9d1d792..ae513b4 100644 --- a/rest/request.go +++ b/rest/request.go @@ -3,6 +3,7 @@ package rest import ( "encoding/json" "errors" + "io" "io/ioutil" "net/http" "net/url" @@ -32,8 +33,12 @@ func (r *Request) PathParam(name string) string { // DecodeJsonPayload reads the request body and decodes the JSON using json.Unmarshal. func (r *Request) DecodeJsonPayload(v interface{}) error { + defer func() { + io.Copy(ioutil.Discard, r.Body) + r.Body.Close() + }() + content, err := ioutil.ReadAll(r.Body) - r.Body.Close() if err != nil { return err }