Merge pull request #6 from Joon-L/joonlee/request-body-from-file

Add support to fetch request body from file
This commit is contained in:
Dmitry Kakurin 2019-11-04 22:24:59 -08:00 коммит произвёл GitHub
Родитель f20ffbeea4 696d3c7a74
Коммит 525c6dd4a6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -38,7 +38,7 @@ Protocol: HTTP/2
OutFile: "out/res.hgrm"
Request:
# HTTPMethod defaults to GET if Body (below) is not present and to POST otherwise, but can be specified explicitly
# HTTPMethod defaults to GET if Body or BodyFile (below) is not present and to POST otherwise, but can be specified explicitly
HTTPMethod: POST
# ExpectedHTTPStatusCode defaults to 200
@ -76,3 +76,6 @@ Request:
}
}
}
# POST request body. This will override the Body above.
BodyFile: path/to/file

Просмотреть файл

@ -69,7 +69,7 @@ func main() {
}
if conf.Request.HTTPMethod == "" {
if conf.Request.Body == "" {
if conf.Request.Body == "" && conf.Request.BodyFile == "" {
conf.Request.HTTPMethod = http.MethodGet
} else {
conf.Request.HTTPMethod = http.MethodPost

Просмотреть файл

@ -92,6 +92,7 @@ type WebRequesterFactory struct {
Hosts []string `yaml:"Hosts"`
Headers map[string]string `yaml:"Headers"`
Body string `yaml:"Body"`
BodyFile string `yaml:"BodyFile"`
ExpectedHTTPStatusCode int `yaml:"ExpectedHTTPStatusCode"`
HTTPMethod string `yaml:"HTTPMethod"`
@ -109,6 +110,13 @@ func (w *WebRequesterFactory) GetRequester(uint64) bench.Requester {
w.expandedHeaders = expandedHeaders
}
// if BodyFile is specified Body is ignored
if w.BodyFile != "" {
content, err := ioutil.ReadFile(w.BodyFile)
maybePanic(err)
w.Body = string(content)
}
return &webRequester{w.URL, w.URLs, w.Hosts, w.expandedHeaders, w.Body, w.ExpectedHTTPStatusCode, w.HTTPMethod}
}