diff --git a/executors/http/README.md b/executors/http/README.md index dbbce11f..7b9e86a8 100644 --- a/executors/http/README.md +++ b/executors/http/README.md @@ -10,6 +10,7 @@ In your yaml file, you can use: - url mandatory - unix_sock (optional) - path (optional) + - query_parameters (optional) - body (optional) - bodyFile (optional) - preserve_bodyfile (optional) skip file content interpolation diff --git a/executors/http/http.go b/executors/http/http.go index 4fa14dde..945a359e 100644 --- a/executors/http/http.go +++ b/executors/http/http.go @@ -36,26 +36,27 @@ type Headers map[string]string // Executor struct. Json and yaml descriptor are used for json output type Executor struct { - Method string `json:"method" yaml:"method"` - URL string `json:"url" yaml:"url"` - Path string `json:"path" yaml:"path"` - Body string `json:"body" yaml:"body"` - BodyFile string `json:"bodyfile" yaml:"bodyfile"` - PreserveBodyFile bool `json:"preserve_bodyfile" yaml:"preserve_bodyfile" mapstructure:"preserve_bodyfile"` - MultipartForm interface{} `json:"multipart_form" yaml:"multipart_form"` - Headers Headers `json:"headers" yaml:"headers"` - IgnoreVerifySSL bool `json:"ignore_verify_ssl" yaml:"ignore_verify_ssl" mapstructure:"ignore_verify_ssl"` - BasicAuthUser string `json:"basic_auth_user" yaml:"basic_auth_user" mapstructure:"basic_auth_user"` - BasicAuthPassword string `json:"basic_auth_password" yaml:"basic_auth_password" mapstructure:"basic_auth_password"` - SkipHeaders bool `json:"skip_headers" yaml:"skip_headers" mapstructure:"skip_headers"` - SkipBody bool `json:"skip_body" yaml:"skip_body" mapstructure:"skip_body"` - Proxy string `json:"proxy" yaml:"proxy" mapstructure:"proxy"` - Resolve []string `json:"resolve" yaml:"resolve" mapstructure:"resolve"` - NoFollowRedirect bool `json:"no_follow_redirect" yaml:"no_follow_redirect" mapstructure:"no_follow_redirect"` - UnixSock string `json:"unix_sock" yaml:"unix_sock" mapstructure:"unix_sock"` - TLSClientCert string `json:"tls_client_cert" yaml:"tls_client_cert" mapstructure:"tls_client_cert"` - TLSClientKey string `json:"tls_client_key" yaml:"tls_client_key" mapstructure:"tls_client_key"` - TLSRootCA string `json:"tls_root_ca" yaml:"tls_root_ca" mapstructure:"tls_root_ca"` + Method string `json:"method" yaml:"method"` + URL string `json:"url" yaml:"url"` + Path string `json:"path" yaml:"path"` + QueryParameters map[string]string `json:"query_parameters" yaml:"query_parameters" mapstructure:"query_parameters"` + Body string `json:"body" yaml:"body"` + BodyFile string `json:"bodyfile" yaml:"bodyfile"` + PreserveBodyFile bool `json:"preserve_bodyfile" yaml:"preserve_bodyfile" mapstructure:"preserve_bodyfile"` + MultipartForm interface{} `json:"multipart_form" yaml:"multipart_form"` + Headers Headers `json:"headers" yaml:"headers"` + IgnoreVerifySSL bool `json:"ignore_verify_ssl" yaml:"ignore_verify_ssl" mapstructure:"ignore_verify_ssl"` + BasicAuthUser string `json:"basic_auth_user" yaml:"basic_auth_user" mapstructure:"basic_auth_user"` + BasicAuthPassword string `json:"basic_auth_password" yaml:"basic_auth_password" mapstructure:"basic_auth_password"` + SkipHeaders bool `json:"skip_headers" yaml:"skip_headers" mapstructure:"skip_headers"` + SkipBody bool `json:"skip_body" yaml:"skip_body" mapstructure:"skip_body"` + Proxy string `json:"proxy" yaml:"proxy" mapstructure:"proxy"` + Resolve []string `json:"resolve" yaml:"resolve" mapstructure:"resolve"` + NoFollowRedirect bool `json:"no_follow_redirect" yaml:"no_follow_redirect" mapstructure:"no_follow_redirect"` + UnixSock string `json:"unix_sock" yaml:"unix_sock" mapstructure:"unix_sock"` + TLSClientCert string `json:"tls_client_cert" yaml:"tls_client_cert" mapstructure:"tls_client_cert"` + TLSClientKey string `json:"tls_client_key" yaml:"tls_client_key" mapstructure:"tls_client_key"` + TLSRootCA string `json:"tls_root_ca" yaml:"tls_root_ca" mapstructure:"tls_root_ca"` } // Result represents a step result. Json and yaml descriptor are used for json output @@ -335,6 +336,20 @@ func (e Executor) getRequest(ctx context.Context, workdir string) (*http.Request return nil, err } } + + if len(e.QueryParameters) > 0 { + baseURL, err := url.Parse(path) + if err != nil { + return nil, fmt.Errorf("unable to parse url %s: %v", path, err) + } + params := url.Values{} + for k, v := range e.QueryParameters { + params.Add(k, v) + } + baseURL.RawQuery = params.Encode() + path = baseURL.String() + } + req, err := http.NewRequest(method, path, body) if err != nil { return nil, err diff --git a/tests/http.yml b/tests/http.yml index cdabc9be..cf95a892 100644 --- a/tests/http.yml +++ b/tests/http.yml @@ -91,3 +91,13 @@ testcases: - result.body ShouldBeEmpty - result.headers ShouldBeEmpty + +- name: get http (with query parameters) + steps: + - type: http + method: GET + url: https://httpbin.org/get + query_parameters: + a: " b" + assertions: + - result.bodyjson.args.a ShouldEqual " b"