Skip to content

Commit

Permalink
Combining dispatching #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelewski committed Dec 12, 2024
1 parent 8bf975d commit 3a34fb5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion quesma/frontend_connectors/basic_http_frontend_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"github.com/ucarion/urlpath"
"io"
"net/http"
"quesma/quesma/recovery"
quesma_api "quesma_v2/core"
"strings"
"sync"
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3a34fb5

Please sign in to comment.