-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
88 lines (77 loc) · 2.46 KB
/
options.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package fastlike
import (
"io"
"net"
"net/http"
"os"
)
// Option is a functional option applied to an Instance at creation time
type Option func(*Instance)
// WithBackend registers an `http.Handler` identified by `name` used for subrequests targeting that
// backend
func WithBackend(name string, h http.Handler) Option {
return func(i *Instance) {
i.addBackend(name, h)
}
}
// WithDefaultBackend is an Option to override the default subrequest backend.
func WithDefaultBackend(fn func(name string) http.Handler) Option {
return func(i *Instance) {
i.defaultBackend = fn
}
}
// WithGeo replaces the default geographic lookup function
func WithGeo(fn func(net.IP) Geo) Option {
return func(i *Instance) {
i.geolookup = fn
}
}
// WithLogger registers a new log endpoint usable from a wasm guest
func WithLogger(name string, w io.Writer) Option {
return func(i *Instance) {
i.addLogger(name, w)
}
}
// WithDefaultLogger sets the default logger used for logs issued by the guest
// This one is different from WithLogger, because it accepts a name and returns a writer so that
// custom implementations can print the name, if they prefer
func WithDefaultLogger(fn func(name string) io.Writer) Option {
return func(i *Instance) {
i.defaultLogger = fn
}
}
// WithDictionary registers a new dictionary with a corresponding lookup function
func WithDictionary(name string, fn LookupFunc) Option {
return func(i *Instance) {
i.addDictionary(name, fn)
}
}
// WithSecureFunc is an Option that determines if a request should be considered "secure" or not.
// If it returns true, the request url has the "https" scheme and the "fastly-ssl" header set when
// going into the wasm program.
// The default implementation checks if `req.TLS` is non-nil.
func WithSecureFunc(fn func(*http.Request) bool) Option {
return func(i *Instance) {
i.secureFn = fn
}
}
// WithUserAgentParser is an Option that converts user agent header values into UserAgent structs,
// called when the guest code uses the user agent parser XQD call.
func WithUserAgentParser(fn UserAgentParser) Option {
return func(i *Instance) {
i.uaparser = fn
}
}
// WithVerbosity controls how verbose the system level logs are.
// A verbosity of 2 prints all calls from the wasm guest into the host methods
// Currently, verbosity less than 2 does nothing
func WithVerbosity(v int) Option {
return func(i *Instance) {
if v >= 2 {
i.abilog.SetOutput(os.Stderr)
}
if v >= 1 {
i.log.SetOutput(os.Stderr)
}
}
}