-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.go
65 lines (52 loc) · 1.63 KB
/
filter.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
package main
import (
"github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/api"
)
type filter struct {
callbacks api.FilterCallbackHandler
path string
config *config
}
func (f *filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.StatusType {
path, _ := header.Get(":path")
f.path = path
if path == "/string" || path == "/byte" {
f.callbacks.SendLocalReply(301, "", map[string]string{"local-reply": "Set"}, -1, "test-from-go")
return api.LocalReply
}
return api.Continue
}
func (f *filter) DecodeData(buffer api.BufferInstance, endStream bool) api.StatusType {
return api.Continue
}
func (f *filter) DecodeTrailers(trailers api.RequestTrailerMap) api.StatusType {
return api.Continue
}
func (f *filter) EncodeHeaders(header api.ResponseHeaderMap, endStream bool) api.StatusType {
if f.path == "/string" {
location := "/another/string/castle"
header.Set("location", location)
}
if f.path == "/byte" {
whereTo := []byte("/another/byte/castle")
location := string(whereTo)
header.Set("location", location)
}
status, _ := header.Get(":status")
if status == "500" || status == "504" {
header.Set("Content-Type", "text/html")
f.callbacks.SendLocalReply(503,
"<b>Bold textM</b>",
map[string]string{"Content-Type": "text/html"}, -1, "custom-500-message")
return api.LocalReply
}
return api.Continue
}
func (f *filter) EncodeData(buffer api.BufferInstance, endStream bool) api.StatusType {
return api.Continue
}
func (f *filter) EncodeTrailers(trailers api.ResponseTrailerMap) api.StatusType {
return api.Continue
}
func (f *filter) OnDestroy(reason api.DestroyReason) {
}