filter

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: BSD-2-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caction added in v1.3.1

type Caction struct {
	Replace []Creplacement `yaml:"replace" json:"replace"`
	Header  []Cheader      `yaml:"header" json:"header"`
}

Caction configuration parts for request and response management.

type Cdump added in v1.3.1

type Cdump struct {
	Folder string   `yaml:"folder" json:"folder"`
	URLs   []string `yaml:"urls" json:"urls"`
}

Cdump configuration parts for dump log.

type Cheader added in v1.3.1

type Cheader struct {
	Name  string `yaml:"name" json:"name"`
	Value string `yaml:"value" json:"value"`
	Force bool   `yaml:"force" json:"force"`
	Add   bool   `yaml:"add" json:"add"`
	UUID  bool   `yaml:"uuid" json:"uuid"`
}

Cheader configuration parts for header management.

type Config added in v1.3.1

type Config struct {
	ContentTypes []string       `yaml:"content-types" json:"content-types"` //nolint: tagliatelle
	Dump         Cdump          `yaml:"dump" json:"dump"`
	Force        bool           `yaml:"force" json:"force"`
	Insecure     bool           `yaml:"insecure" json:"insecure"`
	Port         int            `yaml:"port" json:"port"`
	Prefix       []Creplacement `yaml:"prefix" json:"prefix"`
	Priority     uint8          `yaml:"priority" json:"priority"`
	Replace      []Creplacement `yaml:"replace" json:"replace"`
	Request      Caction        `yaml:"request" json:"request"`
	Response     Caction        `yaml:"response" json:"response"`
	Restricted   []string       `yaml:"restricted" json:"restricted"`
	Status       []string       `yaml:"status" json:"status"`
	Token        []CtokenAction `yaml:"token" json:"token"`
	Type         string         `yaml:"type" json:"type"`
	URL          string         `yaml:"url" json:"url"`
}

Config common structure for configuration regardless the source.

type Creator added in v1.4.0

type Creator interface {
	NewFromYAML(string) (string, uint8, FilteredServer)
	NewFromJSON(string) (string, uint8, FilteredServer)
	NewFromEnv() (string, uint8, FilteredServer)
}

Creator allow mocking of Factory.

func NewFactory added in v1.4.0

func NewFactory(upLog logrus.FieldLogger) Creator

NewFactory returns a Filter Factory.

type Creplacement added in v1.3.1

type Creplacement struct {
	From string   `yaml:"from" json:"from"`
	To   string   `yaml:"to" json:"to"`
	Urls []string `yaml:"urls" json:"urls"`
}

Creplacement configuration parts for replacement.

type CtokenAction added in v1.3.1

type CtokenAction struct {
	Header string `yaml:"header" json:"header"`
	Value  string `yaml:"value" json:"value"`
	Action string `yaml:"action" json:"action"`
}

CtokenAction configuration parts for token management.

type Factory added in v1.4.0

type Factory struct {
	// contains filtered or unexported fields
}

Factory provides way to create a filters.

func (*Factory) NewFromEnv added in v1.4.0

func (f *Factory) NewFromEnv() (string, uint8, FilteredServer)

NewFromEnv instantiate a Filter object from the environment variable configuration. nolint: funlen,gocognit

func (*Factory) NewFromJSON added in v1.4.0

func (f *Factory) NewFromJSON(filePath string) (string, uint8, FilteredServer)

NewFromJSON instantiate a Filter object from the configuration file.

func (*Factory) NewFromYAML added in v1.4.0

func (f *Factory) NewFromYAML(filePath string) (string, uint8, FilteredServer)

NewFromYAML instantiate a Filter object from the configuration file.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter proxifies an URL and filter the response.

func (*Filter) IsConcerned added in v1.1.0

func (f *Filter) IsConcerned(ip net.IP, parsedHeader http.Header) bool

IsConcerned determine if the request fulfil the filter condition.

func (*Filter) IsConditional added in v1.1.0

func (f *Filter) IsConditional() bool

IsConditional returns true if the filter has conditions.

func (*Filter) Kind added in v1.4.0

func (f *Filter) Kind() Type

Kind returns the type of proxy.

func (*Filter) PrefixReplace added in v1.4.0

func (f *Filter) PrefixReplace(URL string) string

PrefixReplace rewrite the current URL with the defined URL prefixes.

func (*Filter) Serve

func (f *Filter) Serve(res http.ResponseWriter, req *http.Request)

Serve starts a filtering http proxy.

func (*Filter) ServeTCP added in v1.4.0

func (f *Filter) ServeTCP() error

ServeTCP listen on the given port and start a goroutine to handle each connection.

func (*Filter) UpdateRequest added in v1.0.2

func (f *Filter) UpdateRequest(r *http.Request)

UpdateRequest will be called back when the request is received by the proxy.

func (*Filter) UpdateResponse

func (f *Filter) UpdateResponse(r *http.Response) error

UpdateResponse will be called back when the proxyfied server respond and filter the response if necessary.

type FilteredServer added in v1.4.0

type FilteredServer interface {
	IsConcerned(net.IP, http.Header) bool
	Serve(http.ResponseWriter, *http.Request)
	ServeTCP() error
	IsConditional() bool
	PrefixReplace(string) string
	Kind() Type
}

FilteredServer represents a reverse proxy.

type Mock added in v1.4.0

type Mock struct {
	Position    int
	Concerned   bool
	Conditional bool

	T *testing.T
	// contains filtered or unexported fields
}

Mock provides a way to mimic a Filter object.

func NewMock added in v1.4.0

func NewMock(
	kind Type,
	position int,
	concerned bool,
	conditional bool,
	reqBody string,
	reqHeader http.Header,
	resBody string,
	resHeader http.Header,
	t *testing.T,
) *Mock

NewMock returns a new mock.

func (*Mock) IsConcerned added in v1.4.0

func (m *Mock) IsConcerned(ip net.IP, h http.Header) bool

IsConcerned mimics the IsConcerned from Filter.

func (*Mock) IsConditional added in v1.4.0

func (m *Mock) IsConditional() bool

IsConditional mimics the IsConditional from Filter.

func (*Mock) Kind added in v1.4.0

func (m *Mock) Kind() Type

Kind mimics the Kind from Filter.

func (*Mock) PrefixReplace added in v1.4.0

func (m *Mock) PrefixReplace(URL string) string

PrefixReplace mimics the PrefixReplace from Filter.

func (*Mock) Serve added in v1.4.0

func (m *Mock) Serve(res http.ResponseWriter, req *http.Request)

Serve mimics the Serve from Filter.

func (*Mock) ServeTCP added in v1.4.0

func (m *Mock) ServeTCP() error

ServeTCP mimics the ServeTCP from Filter.

type Type added in v1.4.0

type Type int

Type defines the kind of proxy.

const (
	// HTTP web connection with replacement.
	HTTP Type = iota
	// TCP raw connection without replacement.
	TCP Type = iota
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL