in lib/http.go [547:585]
func (l httpLib) doPost(args ...ref.Val) ref.Val {
if len(args) != 3 {
return types.NewErr("no such overload for post")
}
url, ok := args[0].(types.String)
if !ok {
return types.ValOrErr(url, "no such overload for request")
}
content, ok := args[1].(types.String)
if !ok {
return types.ValOrErr(content, "no such overload for request")
}
var body io.Reader
switch text := args[2].(type) {
case types.Bytes:
if len(text) != 0 {
body = bytes.NewReader(text)
}
case types.String:
if text != "" {
body = strings.NewReader(string(text))
}
default:
return types.NewErr("invalid type for post body: %s", text.Type())
}
err := l.options.Limiter.Wait(context.TODO())
if err != nil {
return types.NewErr("%s", err)
}
resp, err := l.post(url, content, body)
if err != nil {
return types.NewErr("%s", err)
}
rm, err := respToMap(resp, l.options.MaxBodySize)
if err != nil {
return types.NewErr("%s", err)
}
return types.DefaultTypeAdapter.NativeToValue(rm)
}