mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-22 14:59:34 +02:00
[#3058] soft-deprecated 'data' prop in favour of 'body' to allow raw strings
This commit is contained in:
parent
b3f09ff045
commit
b1093baef7
@ -1,3 +1,10 @@
|
||||
## v0.17.2
|
||||
|
||||
- Soft-deprecated `$http.send({ data: object, ... })` in favour of `$http.send({ body: rawString, ... })`
|
||||
to allow sending non-JSON body with the request ([#3058](https://github.com/pocketbase/pocketbase/discussions/3058)).
|
||||
The existing `data` prop will still work, but it will be recommended to use `body` instead (_to send JSON you can use `JSON.stringify(...)` as body value_).
|
||||
|
||||
|
||||
## v0.17.1
|
||||
|
||||
- Use relative path when redirecting to the OAuth2 providers page in the Admin UI to support subpath deployments ([#3026](https://github.com/pocketbase/pocketbase/pull/3026); thanks @sonyarianto).
|
||||
|
@ -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
|
||||
|
@ -921,8 +921,6 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
|
||||
bodyRaw, _ := io.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
body := map[string]any{}
|
||||
json.Unmarshal(bodyRaw, &body)
|
||||
|
||||
// normalize headers
|
||||
headers := make(map[string]string, len(req.Header))
|
||||
@ -935,7 +933,7 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
info := map[string]any{
|
||||
"method": req.Method,
|
||||
"headers": headers,
|
||||
"body": body,
|
||||
"body": string(bodyRaw),
|
||||
}
|
||||
|
||||
infoRaw, _ := json.Marshal(info)
|
||||
@ -992,8 +990,8 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
const test1 = $http.send({
|
||||
method: "post",
|
||||
url: testUrl,
|
||||
data: {"data": "example"},
|
||||
headers: {"header1": "123", "header2": "456"},
|
||||
body: '789',
|
||||
})
|
||||
|
||||
// with custom content-type header
|
||||
@ -1012,6 +1010,7 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
"json.headers.header1": "123",
|
||||
"json.headers.header2": "456",
|
||||
"json.headers.content_type": "application/json", // default
|
||||
"json.body": "789",
|
||||
}],
|
||||
[test2, {
|
||||
"statusCode": "200",
|
||||
|
5277
plugins/jsvm/internal/types/generated/types.d.ts
vendored
5277
plugins/jsvm/internal/types/generated/types.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -863,11 +863,14 @@ declare namespace $http {
|
||||
* ` + "```" + `
|
||||
*/
|
||||
function send(config: {
|
||||
url: string,
|
||||
url: string,
|
||||
body?: string,
|
||||
method?: string, // default to "GET"
|
||||
data?: { [key:string]: any },
|
||||
headers?: { [key:string]: string },
|
||||
timeout?: number // default to 120
|
||||
timeout?: number, // default to 120
|
||||
|
||||
// deprecated, please use body instead
|
||||
data?: { [key:string]: any },
|
||||
}): {
|
||||
statusCode: number
|
||||
raw: string
|
||||
|
Loading…
x
Reference in New Issue
Block a user