added support for multiple raw requests

This commit is contained in:
Mzack9999 2020-04-29 21:19:35 +02:00
parent f5b6474a11
commit ec7cd50e22

View File

@ -39,8 +39,8 @@ type HTTPRequest struct {
Redirects bool `yaml:"redirects,omitempty"` Redirects bool `yaml:"redirects,omitempty"`
// MaxRedirects is the maximum number of redirects that should be followed. // MaxRedirects is the maximum number of redirects that should be followed.
MaxRedirects int `yaml:"max-redirects,omitempty"` MaxRedirects int `yaml:"max-redirects,omitempty"`
// Raw contains a raw request // Raw contains raw requests
Raw string `yaml:"raw,omitempty"` Raw []string `yaml:"raw,omitempty"`
} }
// GetMatchersCondition returns the condition for the matcher // GetMatchersCondition returns the condition for the matcher
@ -66,7 +66,7 @@ func (r *HTTPRequest) MakeHTTPRequest(baseURL string) ([]*retryablehttp.Request,
"Hostname": hostname, "Hostname": hostname,
} }
if r.Raw != "" { if len(r.Raw) > 0 {
return r.makeHTTPRequestFromRaw(baseURL, values) return r.makeHTTPRequestFromRaw(baseURL, values)
} }
@ -98,9 +98,13 @@ func (r *HTTPRequest) makeHTTPRequestFromModel(baseURL string, values map[string
} }
// makeHTTPRequestFromRaw creates a *http.Request from a raw request // makeHTTPRequestFromRaw creates a *http.Request from a raw request
func (r *HTTPRequest) makeHTTPRequestFromRaw(baseURL string, values map[string]interface{}) ([]*retryablehttp.Request, error) { func (r *HTTPRequest) makeHTTPRequestFromRaw(baseURL string, values map[string]interface{}) (requests []*retryablehttp.Request, err error) {
for _, raw := range r.Raw {
// Add trailing line
raw += "\n"
// Replace the dynamic variables in the URL if any // Replace the dynamic variables in the URL if any
t := fasttemplate.New(r.Raw, "{{", "}}") t := fasttemplate.New(raw, "{{", "}}")
raw := t.ExecuteString(values) raw := t.ExecuteString(values)
// Build a parsed request from raw // Build a parsed request from raw
@ -126,7 +130,10 @@ func (r *HTTPRequest) makeHTTPRequestFromRaw(baseURL string, values map[string]i
return nil, err return nil, err
} }
return []*retryablehttp.Request{request}, nil requests = append(requests, request)
}
return requests, nil
} }
func (r *HTTPRequest) fillRequest(req *http.Request, values map[string]interface{}) (*retryablehttp.Request, error) { func (r *HTTPRequest) fillRequest(req *http.Request, values map[string]interface{}) (*retryablehttp.Request, error) {