You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-24 23:24:00 +02:00
[#3310] added headers and cookies fields to the .send result
This commit is contained in:
@@ -613,9 +613,11 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
vm.Set("$http", obj)
|
||||
|
||||
type sendResult struct {
|
||||
StatusCode int
|
||||
Raw string
|
||||
Json any
|
||||
StatusCode int `json:"statusCode"`
|
||||
Headers map[string][]string `json:"headers"`
|
||||
Cookies map[string]*http.Cookie `json:"cookies"`
|
||||
Raw string `json:"raw"`
|
||||
Json any `json:"json"`
|
||||
}
|
||||
|
||||
type sendConfig struct {
|
||||
@@ -686,9 +688,19 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
|
||||
result := &sendResult{
|
||||
StatusCode: res.StatusCode,
|
||||
Headers: map[string][]string{},
|
||||
Cookies: map[string]*http.Cookie{},
|
||||
Raw: string(bodyRaw),
|
||||
}
|
||||
|
||||
for k, v := range res.Header {
|
||||
result.Headers[k] = v
|
||||
}
|
||||
|
||||
for _, v := range res.Cookies() {
|
||||
result.Cookies[v.Name] = v
|
||||
}
|
||||
|
||||
if len(result.Raw) != 0 {
|
||||
// try as map
|
||||
result.Json = map[string]any{}
|
||||
|
||||
Reference in New Issue
Block a user