diff --git a/quesma/frontend_connectors/basic_http_frontend_connector.go b/quesma/frontend_connectors/basic_http_frontend_connector.go index 8ef9fec64..45355d963 100644 --- a/quesma/frontend_connectors/basic_http_frontend_connector.go +++ b/quesma/frontend_connectors/basic_http_frontend_connector.go @@ -10,7 +10,9 @@ import ( "github.com/ucarion/urlpath" "io" "net/http" + "quesma/quesma/recovery" quesma_api "quesma_v2/core" + "strings" "sync" ) @@ -41,7 +43,24 @@ func (h *BasicHTTPFrontendConnector) GetRouter() quesma_api.Router { func (h *BasicHTTPFrontendConnector) ServeHTTP(w http.ResponseWriter, req *http.Request) { handlers := h.router.GetHandlers() - handlerWrapper := getMatchingHandler(req.URL.Path, handlers) + + defer recovery.LogPanic() + reqBody, err := PeekBodyV2(req) + if err != nil { + http.Error(w, "Error reading request body", http.StatusInternalServerError) + return + } + + quesmaRequest := &quesma_api.Request{ + Method: req.Method, + Path: strings.TrimSuffix(req.URL.Path, "/"), + Params: map[string]string{}, + Headers: req.Header, + QueryParams: req.URL.Query(), + Body: string(reqBody), + } + handlerWrapper, _ := h.router.Matches(quesmaRequest) + handlerWrapper = getMatchingHandler(req.URL.Path, handlers) dispatcher := &quesma_api.Dispatcher{} w = h.responseMutator(w) if handlerWrapper == nil {