Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internals/proxy/middlewares/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func mappingHandler(next http.Handler) http.Handler {
if modifiedBody {
body.Data = bodyData

log.Debug("Applied Data Aliasing: ", body.Data)
err := body.Write(req)

if err != nil {
http.Error(w, "Internal Error", http.StatusInternalServerError)
return
}

body.Write(req)
log.Debug("Applied Data Aliasing: ", body.Data)
}

next.ServeHTTP(w, req)
Expand Down
9 changes: 7 additions & 2 deletions internals/proxy/middlewares/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ func messageHandler(next http.Handler) http.Handler {
if modifiedBody {
body.Data = bodyData

log.Debug("Applied Message Templating: ", body.Data)
err := body.Write(req)

if err != nil {
http.Error(w, "Internal Error", http.StatusInternalServerError)
return
}

body.Write(req)
log.Debug("Applied Message Templating: ", body.Data)
}

next.ServeHTTP(w, req)
Expand Down
9 changes: 7 additions & 2 deletions internals/proxy/middlewares/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ func templateHandler(next http.Handler) http.Handler {
if modifiedBody {
body.Data = bodyData

log.Debug("Applied Body Templating: ", body.Data)
err := body.Write(req)

body.Write(req)
if err != nil {
http.Error(w, "Internal Error", http.StatusInternalServerError)
return
}

log.Debug("Applied Body Templating: ", body.Data)
}

if req.URL.Path != "" {
Expand Down
12 changes: 11 additions & 1 deletion utils/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ func (body Body) ToString() string {
return string(body.Raw)
}

func (body Body) Write(req *http.Request) {
func (body *Body) Write(req *http.Request) error {
newBody, err := CreateBody(body.Data)

if err != nil {
return err
}

body = &newBody

bodyLength := len(body.Raw)

if req.ContentLength != int64(bodyLength) {
Expand All @@ -39,6 +47,8 @@ func (body Body) Write(req *http.Request) {
}

req.Body = io.NopCloser(bytes.NewReader(body.Raw))

return nil
}

func CreateBody(data map[string]any) (Body, error) {
Expand Down