[#6282] soft-deprecated $http.send result.raw field in favour of result.body

This commit is contained in:
Gani Georgiev
2025-04-04 11:32:47 +03:00
parent 409bcdaa96
commit 9f6010d38d
6 changed files with 3100 additions and 2909 deletions

View File

@@ -774,11 +774,15 @@ func httpClientBinds(vm *goja.Runtime) {
})
type sendResult struct {
JSON any `json:"json"`
Headers map[string][]string `json:"headers"`
Cookies map[string]*http.Cookie `json:"cookies"`
Raw string `json:"raw"`
StatusCode int `json:"statusCode"`
JSON any `json:"json"`
Headers map[string][]string `json:"headers"`
Cookies map[string]*http.Cookie `json:"cookies"`
// Deprecated: consider using Body instead
Raw string `json:"raw"`
Body []byte `json:"body"`
StatusCode int `json:"statusCode"`
}
type sendConfig struct {
@@ -883,6 +887,7 @@ func httpClientBinds(vm *goja.Runtime) {
Headers: map[string][]string{},
Cookies: map[string]*http.Cookie{},
Raw: string(bodyRaw),
Body: bodyRaw,
}
for k, v := range res.Header {
@@ -893,7 +898,7 @@ func httpClientBinds(vm *goja.Runtime) {
result.Cookies[v.Name] = v
}
if len(result.Raw) != 0 {
if len(result.Body) > 0 {
// try as map
result.JSON = map[string]any{}
if err := json.Unmarshal(bodyRaw, &result.JSON); err != nil {