forked from syumai/workers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
property.go
46 lines (38 loc) · 1.04 KB
/
property.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package fetch
import (
"github.com/tinyredglasses/workers/jsutil"
"syscall/js"
)
// RedirectMode represents the redirect mode of a fetch() request.
type RedirectMode string
var (
RedirectModeFollow RedirectMode = "follow"
RedirectModeError RedirectMode = "error"
RedirectModeManual RedirectMode = "manual"
)
func (mode RedirectMode) IsValid() bool {
return mode == RedirectModeFollow || mode == RedirectModeError || mode == RedirectModeManual
}
func (mode RedirectMode) String() string {
return string(mode)
}
// RequestInit represents the options passed to a fetch() request.
type RequestInit struct {
CF *RequestInitCF
Redirect RedirectMode
}
// ToJS converts RequestInit to JS object.
func (init *RequestInit) ToJS() js.Value {
if init == nil {
return js.Undefined()
}
obj := jsutil.NewObject()
if init.Redirect.IsValid() {
obj.Set("redirect", init.Redirect.String())
}
return obj
}
// RequestInitCF represents the Cloudflare-specific options passed to a fetch() request.
type RequestInitCF struct {
/* TODO: implement */
}