From 1e4d56d0594bb104656e4e976a6ec1def8edf32d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 6 Feb 2021 18:53:25 +0300 Subject: [PATCH] fix body parsing Signed-off-by: Vasiliy Tolstov --- handler.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/handler.go b/handler.go index 7e4d5c0..cdf6005 100644 --- a/handler.go +++ b/handler.go @@ -3,6 +3,7 @@ package http import ( "context" "fmt" + "io" "net/http" "reflect" "strings" @@ -67,6 +68,8 @@ func (h *httpHandler) Options() server.HandlerOptions { func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + defer r.Body.Close() + path := r.URL.Path if !strings.HasPrefix(path, "/") { h.errorHandler(ctx, h, w, r, fmt.Errorf("path must contains /"), http.StatusBadRequest) @@ -156,6 +159,10 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { //function := hldr.rcvr var returnValues []reflect.Value + if err = cf.ReadBody(r.Body, argv.Interface()); err != nil && err != io.EOF { + h.errorHandler(ctx, h, w, r, err, http.StatusInternalServerError) + } + matches = rflutil.FlattenMap(matches) if err = rflutil.MergeMap(argv.Interface(), matches); err != nil { h.errorHandler(ctx, h, w, r, err, http.StatusBadRequest)