@@ -14,6 +14,7 @@ import (
1414 log "github.com/codeshelldev/secured-signal-api/utils/logger"
1515 query "github.com/codeshelldev/secured-signal-api/utils/query"
1616 request "github.com/codeshelldev/secured-signal-api/utils/request"
17+ "github.com/codeshelldev/secured-signal-api/utils/request/requestkeys"
1718 templating "github.com/codeshelldev/secured-signal-api/utils/templating"
1819)
1920
@@ -30,10 +31,11 @@ func templateHandler(next http.Handler) http.Handler {
3031 variables = getSettings ("*" ).MESSAGE .VARIABLES
3132 }
3233
33- body , err := request .GetReqBody (w , req )
34+ body , err := request .GetReqBody (req )
3435
3536 if err != nil {
3637 log .Error ("Could not get Request Body: " , err .Error ())
38+ http .Error (w , "Bad Request: invalid body" , http .StatusBadRequest )
3739 }
3840
3941 bodyData := map [string ]any {}
@@ -146,39 +148,39 @@ func prefixData(prefix string, data map[string]any) map[string]any {
146148 return res
147149}
148150
149- func cleanHeaders (headers map [string ]any ) map [string ]any {
150- cleanedHeaders := map [string ]any {}
151+ func cleanHeaders (headers map [string ][] string ) map [string ][] string {
152+ cleanedHeaders := map [string ][] string {}
151153
152154 for key , value := range headers {
153155 cleanedKey := strings .ReplaceAll (key , "-" , "_" )
154156
155157 cleanedHeaders [cleanedKey ] = value
156158 }
157159
158- authHeader , ok := cleanedHeaders ["Authorization" ].([] string )
160+ authHeader , ok := cleanedHeaders ["Authorization" ]
159161
160162 if ! ok {
161163 authHeader = []string {"UNKNOWN REDACTED" }
162164 }
163165
164- cleanedHeaders ["Authorization" ] = strings .Split (authHeader [0 ], ` ` )[0 ] + " REDACTED"
166+ cleanedHeaders ["Authorization" ] = [] string { strings .Split (authHeader [0 ], ` ` )[0 ] + " REDACTED" }
165167
166168 return cleanedHeaders
167169}
168170
169- func TemplateBody (body map [string ]any , headers map [string ]any , VARIABLES map [string ]any ) (map [string ]any , bool , error ) {
171+ func TemplateBody (body map [string ]any , headers map [string ][] string , VARIABLES map [string ]any ) (map [string ]any , bool , error ) {
170172 var modified bool
171173
172174 headers = cleanHeaders (headers )
173175
174- // Normalize # Var and @ Var to .header_key_Var and .body_key_Var
175- normalizedBody , err := normalizeData ("@" , "body_key_" , body )
176+ // Normalize `keys.BodyPrefix` + " Var" and `keys.HeaderPrefix` + " Var" to "" .header_key_Var" and " .body_key_Var"
177+ normalizedBody , err := normalizeData (requestkeys . BodyPrefix , "body_key_" , body )
176178
177179 if err != nil {
178180 return body , false , err
179181 }
180182
181- normalizedBody , err = normalizeData ("#" , "header_key_" , normalizedBody )
183+ normalizedBody , err = normalizeData (requestkeys . HeaderPrefix , "header_key_" , normalizedBody )
182184
183185 if err != nil {
184186 return body , false , err
@@ -188,7 +190,7 @@ func TemplateBody(body map[string]any, headers map[string]any, VARIABLES map[str
188190 prefixedBody := prefixData ("body_key_" , normalizedBody )
189191
190192 // Prefix Header Data with header_key_
191- prefixedHeaders := prefixData ("header_key_" , headers )
193+ prefixedHeaders := prefixData ("header_key_" , request . ParseHeaders ( headers ) )
192194
193195 variables := VARIABLES
194196
0 commit comments