From c346087926cd8d3550c46e52374f09d54ea27105 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Fri, 17 Jul 2020 15:07:34 +0200 Subject: [PATCH] limited support for same template extraction+reuse --- v2/pkg/executer/executer_http.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/v2/pkg/executer/executer_http.go b/v2/pkg/executer/executer_http.go index ca3b3a46..b09f38c2 100644 --- a/v2/pkg/executer/executer_http.go +++ b/v2/pkg/executer/executer_http.go @@ -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{}