1
0
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:
Gani Georgiev
2023-09-14 14:45:05 +03:00
parent 2608efb56c
commit bb0a2dd698
36 changed files with 3760 additions and 3731 deletions

View File

@@ -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{}