Skip to content

Commit

Permalink
filter manager: part 2, support local reply (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Nov 10, 2023
1 parent d50121a commit d171ffb
Show file tree
Hide file tree
Showing 12 changed files with 825 additions and 111 deletions.
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ linters-settings:
package-average: 10
skip-tests: true
gocritic:
enabled-tags:
- diagnostic
disabled-tags:
- style
- experimental
- opinionated
unparam:
check-exported: false

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ lint-spell: build-dev-tools
.PHONY: lint-spell-local
lint-spell-local:
codespell --skip '.git,.idea,test-envoy,go.mod,go.sum,*.svg' --check-filenames --check-hidden --ignore-words ./.ignore_words

.PHONY: lint
lint: lint-go fmt-go lint-spell
63 changes: 43 additions & 20 deletions pkg/filtermanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,67 @@ import (
"github.com/envoyproxy/envoy/contrib/golang/common/go/api"
)

type DecodeWholeRequestFilter interface {
NeedDecodeWholeRequest(headers api.RequestHeaderMap) bool
DecodeRequest(headers api.RequestHeaderMap, data api.BufferInstance, trailers api.RequestTrailerMap) ResultAction
}

type EncodeWholeResponseFilter interface {
NeedEncodeWholeResponse(headers api.ResponseHeaderMap) bool
EncodeResponse(headers api.ResponseHeaderMap, data api.BufferInstance, trailers api.ResponseTrailerMap) ResultAction
}

type Filter interface {
DecodeHeaders(RequestHeaderMap, bool)
DecodeData(BufferInstance, bool)
DecodeTrailers(RequestTrailerMap)
DecodeHeaders(headers RequestHeaderMap, endStream bool) ResultAction
DecodeData(data BufferInstance, endStream bool) ResultAction
DecodeTrailers(trailers RequestTrailerMap) ResultAction

EncodeHeaders(ResponseHeaderMap, bool)
EncodeData(BufferInstance, bool)
EncodeTrailers(ResponseTrailerMap)
EncodeHeaders(headers ResponseHeaderMap, endStream bool) ResultAction
EncodeData(data BufferInstance, endStream bool) ResultAction
EncodeTrailers(trailers ResponseTrailerMap) ResultAction

OnLog()

DecodeWholeRequestFilter
EncodeWholeResponseFilter
}

type PassThroughFilter struct{}

func (f *PassThroughFilter) DecodeHeaders(headers RequestHeaderMap, endStream bool) {}
func (f *PassThroughFilter) DecodeHeaders(headers RequestHeaderMap, endStream bool) ResultAction {
return Continue
}

func (f *PassThroughFilter) DecodeData(data BufferInstance, endStream bool) {}
func (f *PassThroughFilter) DecodeData(data BufferInstance, endStream bool) ResultAction {
return Continue
}

func (f *PassThroughFilter) DecodeTrailers(trailers RequestTrailerMap) {}
func (f *PassThroughFilter) DecodeTrailers(trailers RequestTrailerMap) ResultAction {
return Continue
}

func (f *PassThroughFilter) EncodeHeaders(headers ResponseHeaderMap, endStream bool) {}
func (f *PassThroughFilter) EncodeHeaders(headers ResponseHeaderMap, endStream bool) ResultAction {
return Continue
}

func (f *PassThroughFilter) EncodeData(data BufferInstance, endStream bool) {}
func (f *PassThroughFilter) EncodeData(data BufferInstance, endStream bool) ResultAction {
return Continue
}

func (f *PassThroughFilter) EncodeTrailers(trailers ResponseTrailerMap) {}
func (f *PassThroughFilter) EncodeTrailers(trailers ResponseTrailerMap) ResultAction {
return Continue
}

func (f *PassThroughFilter) OnLog() {}

type DecodeWholeRequestFilter interface {
NeedDecodeWholeRequest(headers api.RequestHeaderMap) bool
DecodeRequest(headers api.RequestHeaderMap, buf api.BufferInstance, trailers api.RequestTrailerMap)
func (f *PassThroughFilter) NeedDecodeWholeRequest(headers api.RequestHeaderMap) bool { return false }
func (f *PassThroughFilter) DecodeRequest(headers api.RequestHeaderMap, data api.BufferInstance, trailers api.RequestTrailerMap) ResultAction {
return Continue
}

type EncodeWholeResponseFilter interface {
NeedEncodeWholeResponse(headers api.ResponseHeaderMap) bool
EncodeResponse(headers api.ResponseHeaderMap, buf api.BufferInstance, trailers api.ResponseTrailerMap)
func (f *PassThroughFilter) NeedEncodeWholeResponse(headers api.ResponseHeaderMap) bool { return false }
func (f *PassThroughFilter) EncodeResponse(headers api.ResponseHeaderMap, data api.BufferInstance, trailers api.ResponseTrailerMap) ResultAction {
return Continue
}

type RequestHeaderMap = api.RequestHeaderMap
Expand All @@ -59,8 +84,6 @@ type FilterCallbackHandler interface {
StreamInfo() StreamInfo
RecoverPanic()
GetProperty(key string) (string, error)
// TODO: remove it later
SendLocalReply(responseCode int, bodyText string, headers map[string]string, grpcStatus int64, details string)
}

type FilterFactory func(callbacks FilterCallbackHandler) Filter
Expand Down
23 changes: 23 additions & 0 deletions pkg/filtermanager/api/result_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package api

import "net/http"

type ResultAction interface {
OK()
}
type isResultAction struct {
}

var (
Continue ResultAction = nil
)

func (i *isResultAction) OK() {}

type LocalResponse struct {
isResultAction

Code int
Msg string
Header http.Header
}
Loading

0 comments on commit d171ffb

Please sign in to comment.