mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 23:11:21 +08:00
fix: build url, handle request params
This commit is contained in:
@@ -28,24 +28,34 @@ type Parser struct {
|
||||
plugin funplugin.IPlugin // plugin is used to call functions
|
||||
}
|
||||
|
||||
func buildURL(baseURL, stepURL string) (fullUrl string) {
|
||||
func buildURL(baseURL, stepURL string, queryParams url.Values) (fullUrl *url.URL) {
|
||||
uStep, err := url.Parse(stepURL)
|
||||
if err != nil {
|
||||
log.Error().Str("stepURL", stepURL).Err(err).Msg("[buildURL] parse url failed")
|
||||
return stepURL
|
||||
return nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// append query params
|
||||
if paramStr := queryParams.Encode(); paramStr != "" {
|
||||
if uStep.RawQuery == "" {
|
||||
uStep.RawQuery = paramStr
|
||||
} else {
|
||||
uStep.RawQuery = uStep.RawQuery + "&" + paramStr
|
||||
}
|
||||
}
|
||||
|
||||
// ensure path suffix '/' exists
|
||||
if uStep.RawQuery == "" {
|
||||
uStep.Path = strings.TrimRight(uStep.Path, "/") + "/"
|
||||
}
|
||||
fullUrl = uStep.String()
|
||||
|
||||
fullUrl = uStep
|
||||
}()
|
||||
|
||||
// step url is absolute url
|
||||
if uStep.Host != "" {
|
||||
return
|
||||
return uStep
|
||||
}
|
||||
|
||||
// step url is relative, based on base url
|
||||
@@ -59,7 +69,7 @@ func buildURL(baseURL, stepURL string) (fullUrl string) {
|
||||
uStep.Scheme = uConfig.Scheme
|
||||
uStep.Host = uConfig.Host
|
||||
uStep.Path = path.Join(uConfig.Path, uStep.Path)
|
||||
return
|
||||
return uStep
|
||||
}
|
||||
|
||||
func (p *Parser) ParseHeaders(rawHeaders map[string]string, variablesMapping map[string]interface{}) (map[string]string, error) {
|
||||
|
||||
Reference in New Issue
Block a user