Skip to content

Commit

Permalink
limited support for same template extraction+reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jul 17, 2020
1 parent 6671343 commit c346087
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ mainLoop:
return
}
e.setCustomHeaders(compiledRequest)
e.setDynamicValues(compiledRequest, result.Extractions)
req := compiledRequest.Request

if e.debug {
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit c346087

Please sign in to comment.