fix body parsing

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-06 18:53:25 +03:00
parent 6565336c1a
commit 1e4d56d059

View File

@ -3,6 +3,7 @@ package http
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"net/http" "net/http"
"reflect" "reflect"
"strings" "strings"
@ -67,6 +68,8 @@ func (h *httpHandler) Options() server.HandlerOptions {
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
defer r.Body.Close()
path := r.URL.Path path := r.URL.Path
if !strings.HasPrefix(path, "/") { if !strings.HasPrefix(path, "/") {
h.errorHandler(ctx, h, w, r, fmt.Errorf("path must contains /"), http.StatusBadRequest) 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 //function := hldr.rcvr
var returnValues []reflect.Value 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) matches = rflutil.FlattenMap(matches)
if err = rflutil.MergeMap(argv.Interface(), matches); err != nil { if err = rflutil.MergeMap(argv.Interface(), matches); err != nil {
h.errorHandler(ctx, h, w, r, err, http.StatusBadRequest) h.errorHandler(ctx, h, w, r, err, http.StatusBadRequest)