Skip to content

Commit

Permalink
Add comment about the undefined body hack
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Mar 1, 2022
1 parent 7cd7bc4 commit d18db70
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/modules/k6/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ func (r *RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
// wrappers (facades) that convert the old k6 idiosyncratic APIs to the new
// proper Client ones that accept Request objects and don't suck
mustExport("get", func(url goja.Value, args ...goja.Value) (*Response, error) {
args = append([]goja.Value{goja.Undefined()}, args...) // sigh
// http.get(url, params) doesn't have a body argument, so we add undefined
// as the third argument to http.request(method, url, body, params)
args = append([]goja.Value{goja.Undefined()}, args...)
return mi.defaultClient.Request(http.MethodGet, url, args...)
})
mustExport("head", func(url goja.Value, args ...goja.Value) (*Response, error) {
args = append([]goja.Value{goja.Undefined()}, args...) // sigh
// http.head(url, params) doesn't have a body argument, so we add undefined
// as the third argument to http.request(method, url, body, params)
args = append([]goja.Value{goja.Undefined()}, args...)
return mi.defaultClient.Request(http.MethodHead, url, args...)
})
mustExport("post", mi.defaultClient.getMethodClosure(http.MethodPost))
Expand Down

0 comments on commit d18db70

Please sign in to comment.