зеркало из https://github.com/microsoft/LaBench.git
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:
Коммит
525c6dd4a6
|
@ -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
|
||||
|
|
2
main.go
2
main.go
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче