[#3058] soft-deprecated 'data' prop in favour of 'body' to allow raw strings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user