[#3058] soft-deprecated 'data' prop in favour of 'body' to allow raw strings

This commit is contained in:
Gani Georgiev
2023-08-03 12:31:50 +03:00
parent b3f09ff045
commit b1093baef7
5 changed files with 2665 additions and 2646 deletions
+9 -2
View File
@@ -578,9 +578,10 @@ func httpClientBinds(vm *goja.Runtime) {
type sendConfig struct {
Method string
Url string
Data map[string]any
Body string
Headers map[string]string
Timeout int // seconds (default to 120)
Timeout int // seconds (default to 120)
Data map[string]any // deprecated, consider using Body instead
}
obj.Set("send", func(params map[string]any) (*sendResult, error) {
@@ -604,6 +605,8 @@ func httpClientBinds(vm *goja.Runtime) {
defer cancel()
var reqBody io.Reader
// legacy json body data
if len(config.Data) != 0 {
encoded, err := json.Marshal(config.Data)
if err != nil {
@@ -612,6 +615,10 @@ func httpClientBinds(vm *goja.Runtime) {
reqBody = bytes.NewReader(encoded)
}
if config.Body != "" {
reqBody = strings.NewReader(config.Body)
}
req, err := http.NewRequestWithContext(ctx, strings.ToUpper(config.Method), config.Url, reqBody)
if err != nil {
return nil, err