/
options.go
40 lines (34 loc) · 1.19 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
package fastlike
import (
"log"
"net/http"
)
// InstanceOption is a functional option applied to an Instance when it's created
type InstanceOption func(*Instance)
// BackendHandlerOption is an InstanceOption which configures how subrequests are issued by backend
func BackendHandlerOption(b BackendHandler) InstanceOption {
return func(i *Instance) {
i.backends = b
}
}
// GeoHandlerOption is an InstanceOption which controls how geographic requests are handled
func GeoHandlerOption(b http.Handler) InstanceOption {
return func(i *Instance) {
i.geobackend = b
}
}
// LoggerConfigOption is an InstanceOption that allows configuring the loggers
func LoggerConfigOption(fn func(logger, abilogger *log.Logger)) InstanceOption {
return func(i *Instance) {
fn(i.log, i.abilog)
}
}
// SecureRequestOption is an InstanceOption 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 SecureRequestOption(fn func(*http.Request) bool) InstanceOption {
return func(i *Instance) {
i.isSecure = fn
}
}