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)