-
Notifications
You must be signed in to change notification settings - Fork 350
/
tee.go
43 lines (33 loc) · 823 Bytes
/
tee.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
package tee
import (
"net/http"
"github.com/zalando/skipper/predicates"
"github.com/zalando/skipper/routing"
)
const (
// Deprecated, use predicates.TeeName instead
PredicateName = predicates.TeeName
HeaderKey = "x-tee-loopback-key"
)
type spec struct{}
type predicate struct {
key string
}
func New() routing.PredicateSpec { return &spec{} }
func (s *spec) Name() string { return predicates.TeeName }
func (s *spec) Create(args []interface{}) (routing.Predicate, error) {
if len(args) != 1 {
return nil, predicates.ErrInvalidPredicateParameters
}
teeKey, _ := args[0].(string)
if teeKey == "" {
return nil, predicates.ErrInvalidPredicateParameters
}
return &predicate{
key: teeKey,
}, nil
}
func (p *predicate) Match(r *http.Request) bool {
v := r.Header.Get(HeaderKey)
return v == p.key
}