limited support for same template extraction+reuse

dev
Mzack9999 2020-07-17 15:07:34 +02:00
parent 66713434f8
commit c346087926
1 changed files with 18 additions and 0 deletions

View File

@ -124,6 +124,7 @@ mainLoop:
return
}
e.setCustomHeaders(compiledRequest)
e.setDynamicValues(compiledRequest, result.Extractions)
req := compiledRequest.Request
if e.debug {
@ -307,6 +308,23 @@ func (e *HTTPExecuter) setCustomHeaders(r *requests.CompiledHTTP) {
}
}
// for now supports only headers
func (e *HTTPExecuter) setDynamicValues(r *requests.CompiledHTTP, dynamicValues map[string]interface{}) {
for dk, dv := range dynamicValues {
// replace within header values
for k, v := range r.Request.Header {
for i, vv := range v {
if strings.Contains(vv, "{{"+dk+"}}") {
// coerce values to string and picks only the first value
if dvv, ok := dv.([]string); ok && len(dvv) > 0 {
r.Request.Header[k][i] = strings.ReplaceAll(r.Request.Header[k][i], "{{"+dk+"}}", dvv[0])
}
}
}
}
}
}
type Result struct {
Meta map[string]interface{}
Matches map[string]interface{}