prifma

package
v0.3.29 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusClientClosedRequest     = 499
	StatusTextClientClosedRequest = "Client Closed Request"
)

Variables

View Source
var ErrOutgoingIpNotDefined = errors.New("outgoing ip address wasn't defined")

Functions

This section is empty.

Types

type AfterWriteResponseModule

type AfterWriteResponseModule interface {
	AfterWriteResponse(req *http.Request, resp Response) error
}

type BeforeHandleRequestModule

type BeforeHandleRequestModule interface {
	BeforeHandleRequest(req *http.Request) error
}

type Condition

type Condition interface {
	Test(req *http.Request) bool
}

func NewCondition

func NewCondition(key string, typ string, val string) (Condition, error)

type ConditionDstDomain

type ConditionDstDomain struct {
	Tester ConditionTester
}

func NewConditionDstDomain

func NewConditionDstDomain(tester ConditionTester) *ConditionDstDomain

func (*ConditionDstDomain) Test

func (t *ConditionDstDomain) Test(req *http.Request) bool

type ConditionDstUrl added in v0.3.1

type ConditionDstUrl struct {
	Tester ConditionTester
}

func NewConditionDstUrl added in v0.3.1

func NewConditionDstUrl(tester ConditionTester) *ConditionDstUrl

func (*ConditionDstUrl) Test added in v0.3.1

func (t *ConditionDstUrl) Test(req *http.Request) bool

type ConditionHeader

type ConditionHeader struct {
	Tester ConditionTester
	Name   string
}

func NewConditionHeader

func NewConditionHeader(tester ConditionTester, key string) *ConditionHeader

func (*ConditionHeader) Test

func (t *ConditionHeader) Test(req *http.Request) bool

type ConditionSrcIp

type ConditionSrcIp struct {
	Tester ConditionTester
}

func NewConditionSrcIp

func NewConditionSrcIp(tester ConditionTester) *ConditionSrcIp

func (*ConditionSrcIp) Test

func (t *ConditionSrcIp) Test(req *http.Request) bool

type ConditionTester

type ConditionTester interface {
	Test(val string) bool
}

func NewConditionTester

func NewConditionTester(typ string, val string) (tester ConditionTester, err error)

type ConditionTesterCIDR

type ConditionTesterCIDR struct {
	Net *net.IPNet
}

func NewConditionTesterCIDR

func NewConditionTesterCIDR(val string) (*ConditionTesterCIDR, error)

func (*ConditionTesterCIDR) Test

func (t *ConditionTesterCIDR) Test(val string) bool

type ConditionTesterEquals

type ConditionTesterEquals struct {
	Value string
}

func NewConditionTesterEquals

func NewConditionTesterEquals(val string) (*ConditionTesterEquals, error)

func (*ConditionTesterEquals) Test

func (t *ConditionTesterEquals) Test(val string) bool

type ConditionTesterNegation added in v0.3.25

type ConditionTesterNegation struct {
	Tester ConditionTester
}

func NewConditionTesterNegation added in v0.3.25

func NewConditionTesterNegation(tester ConditionTester) *ConditionTesterNegation

func (*ConditionTesterNegation) Test added in v0.3.25

func (t *ConditionTesterNegation) Test(val string) bool

type ConditionTesterRegexp

type ConditionTesterRegexp struct {
	Regexp *regexp.Regexp
}

func NewConditionTesterRegexp

func NewConditionTesterRegexp(val string) (*ConditionTesterRegexp, error)

func (*ConditionTesterRegexp) Test

func (t *ConditionTesterRegexp) Test(val string) bool

type ConditionUser added in v0.3.2

type ConditionUser struct {
	Tester ConditionTester
}

func NewConditionUser added in v0.3.2

func NewConditionUser(tester ConditionTester) *ConditionUser

func (*ConditionUser) Test added in v0.3.2

func (t *ConditionUser) Test(req *http.Request) bool

type ConfigMain

type ConfigMain struct {
	ConfigServer conf.Block
	ConfigModule conf.Block
}

func NewConfigMain

func NewConfigMain(server Server) *ConfigMain

func (*ConfigMain) Call

func (t *ConfigMain) Call(command conf.Command) error

func (*ConfigMain) CallBlock

func (t *ConfigMain) CallBlock(command conf.Command) (conf.Block, error)

type ConfigModule

type ConfigModule struct {
	ModulesManager ModulesManager
	Conds          []Condition
}

func NewConfigModule

func NewConfigModule(modulesManager ModulesManager) *ConfigModule

func (*ConfigModule) Call

func (t *ConfigModule) Call(command conf.Command) error

func (*ConfigModule) CallBlock

func (t *ConfigModule) CallBlock(command conf.Command) (conf.Block, error)

func (*ConfigModule) CallCondition

func (t *ConfigModule) CallCondition(command conf.Command) (conf.Block, error)

type ConfigServer

type ConfigServer struct {
	Server Server
}

func NewConfigServer

func NewConfigServer(server Server) *ConfigServer

func (*ConfigServer) Call

func (t *ConfigServer) Call(command conf.Command) (err error)

func (*ConfigServer) CallBlock

func (t *ConfigServer) CallBlock(command conf.Command) (conf.Block, error)

type DNS added in v0.3.10

type DNS interface {
	SetCache(host string, ips DNSIps)
	ClearCache()

	LookupIp(host string) (DNSIps, error)
}

type DNSIps added in v0.3.10

type DNSIps struct {
	IpV4 net.IP
	IpV6 net.IP
}

type DefaultDNS added in v0.3.10

type DefaultDNS map[string]DNSIps

func NewDNS added in v0.3.10

func NewDNS() DefaultDNS

func (DefaultDNS) ClearCache added in v0.3.10

func (t DefaultDNS) ClearCache()

func (DefaultDNS) LookupIp added in v0.3.10

func (t DefaultDNS) LookupIp(host string) (DNSIps, error)

func (DefaultDNS) SetCache added in v0.3.10

func (t DefaultDNS) SetCache(host string, ips DNSIps)

type DefaultDialer

type DefaultDialer struct {
	IpV4   net.IP
	IpV6   net.IP
	Dialer net.Dialer
}

func NewDialer

func NewDialer() *DefaultDialer

func (*DefaultDialer) DialContext

func (t *DefaultDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

func (*DefaultDialer) GetIpV4

func (t *DefaultDialer) GetIpV4() net.IP

func (*DefaultDialer) GetIpV6

func (t *DefaultDialer) GetIpV6() net.IP

func (*DefaultDialer) GetLocalIp

func (t *DefaultDialer) GetLocalIp(hostname string) (net.IP, error)

func (*DefaultDialer) SetIpV4

func (t *DefaultDialer) SetIpV4(ip net.IP)

func (*DefaultDialer) SetIpV6

func (t *DefaultDialer) SetIpV6(ip net.IP)

type DefaultHandleRequestResult

type DefaultHandleRequestResult struct {
	Server    Server
	Request   *http.Request
	Response  Response
	Dialer    Dialer
	Transport *http.Transport
}

func NewHandleRequestResult

func NewHandleRequestResult(req *http.Request, server Server) *DefaultHandleRequestResult

func (*DefaultHandleRequestResult) DialContext

func (t *DefaultHandleRequestResult) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

func (*DefaultHandleRequestResult) GetDialer

func (t *DefaultHandleRequestResult) GetDialer() Dialer

func (*DefaultHandleRequestResult) GetProxy

func (t *DefaultHandleRequestResult) GetProxy() ProxyFunc

func (*DefaultHandleRequestResult) GetProxyConnectHeader

func (t *DefaultHandleRequestResult) GetProxyConnectHeader() http.Header

func (*DefaultHandleRequestResult) GetRequest

func (t *DefaultHandleRequestResult) GetRequest() *http.Request

func (*DefaultHandleRequestResult) GetResponse

func (t *DefaultHandleRequestResult) GetResponse() Response

func (*DefaultHandleRequestResult) GetRoundTripper

func (t *DefaultHandleRequestResult) GetRoundTripper() http.RoundTripper

func (*DefaultHandleRequestResult) GetServer

func (t *DefaultHandleRequestResult) GetServer() Server

func (*DefaultHandleRequestResult) SetDialer

func (t *DefaultHandleRequestResult) SetDialer(dialer Dialer)

func (*DefaultHandleRequestResult) SetProxy

func (t *DefaultHandleRequestResult) SetProxy(proxy ProxyFunc)

func (*DefaultHandleRequestResult) SetProxyConnectHeader

func (t *DefaultHandleRequestResult) SetProxyConnectHeader(header http.Header)

func (*DefaultHandleRequestResult) SetRequest

func (t *DefaultHandleRequestResult) SetRequest(req *http.Request)

func (*DefaultHandleRequestResult) SetResponse

func (t *DefaultHandleRequestResult) SetResponse(resp Response)

type DefaultModulesManager

type DefaultModulesManager struct {
	ModulesArray []Module
	ModulesMap   map[string]int
	CondModules  map[Condition]ModulesManager
}

func NewModulesManager

func NewModulesManager(modules ...Module) *DefaultModulesManager

func (*DefaultModulesManager) GetModule

func (t *DefaultModulesManager) GetModule(directive string, conds ...Condition) Module

func (*DefaultModulesManager) GetModulesForRequest

func (t *DefaultModulesManager) GetModulesForRequest(req *http.Request) []Module

type DefaultServer

type DefaultServer struct {
	ModulesManager ModulesManager
	ListenType     ListenType
	ErrorLog       *log.Logger
	DebugLog       *log.Logger
	CertFile       string
	KeyFile        string
	Config         conf.Block
	Server         http.Server
}

func NewServer

func NewServer(modules ...Module) *DefaultServer

func (*DefaultServer) GetCertFile added in v0.3.8

func (t *DefaultServer) GetCertFile() string

func (*DefaultServer) GetDebugLog added in v0.3.27

func (t *DefaultServer) GetDebugLog() *log.Logger

func (*DefaultServer) GetErrorLog

func (t *DefaultServer) GetErrorLog() *log.Logger

func (*DefaultServer) GetIdleTimeout

func (t *DefaultServer) GetIdleTimeout() time.Duration

func (*DefaultServer) GetKeyFile added in v0.3.8

func (t *DefaultServer) GetKeyFile() string

func (*DefaultServer) GetListenIp

func (t *DefaultServer) GetListenIp() net.IP

func (*DefaultServer) GetListenPort

func (t *DefaultServer) GetListenPort() int

func (*DefaultServer) GetListenType

func (t *DefaultServer) GetListenType() ListenType

func (*DefaultServer) GetModulesManager

func (t *DefaultServer) GetModulesManager() ModulesManager

func (*DefaultServer) GetReadHeaderTimeout

func (t *DefaultServer) GetReadHeaderTimeout() time.Duration

func (*DefaultServer) GetReadTimeout

func (t *DefaultServer) GetReadTimeout() time.Duration

func (*DefaultServer) GetWriteTimeout

func (t *DefaultServer) GetWriteTimeout() time.Duration

func (*DefaultServer) ListenAndServe

func (t *DefaultServer) ListenAndServe() error

func (*DefaultServer) LoadConfig

func (t *DefaultServer) LoadConfig(filename string) error

func (*DefaultServer) SetCertFile added in v0.3.8

func (t *DefaultServer) SetCertFile(filename string)

func (*DefaultServer) SetDebugLog added in v0.3.27

func (t *DefaultServer) SetDebugLog(filename string) error

func (*DefaultServer) SetErrorLog

func (t *DefaultServer) SetErrorLog(filename string) error

func (*DefaultServer) SetIdleTimeout

func (t *DefaultServer) SetIdleTimeout(timeout string) error

func (*DefaultServer) SetKeyFile added in v0.3.8

func (t *DefaultServer) SetKeyFile(filename string)

func (*DefaultServer) SetListenIp

func (t *DefaultServer) SetListenIp(ip string) error

func (*DefaultServer) SetListenPort

func (t *DefaultServer) SetListenPort(port string) error

func (*DefaultServer) SetListenType

func (t *DefaultServer) SetListenType(typ string) error

func (*DefaultServer) SetReadHeaderTimeout

func (t *DefaultServer) SetReadHeaderTimeout(timeout string) error

func (*DefaultServer) SetReadTimeout

func (t *DefaultServer) SetReadTimeout(timeout string) error

func (*DefaultServer) SetWriteTimeout

func (t *DefaultServer) SetWriteTimeout(timeout string) error

type Dialer

type Dialer interface {
	GetIpV4() net.IP
	GetIpV6() net.IP
	GetLocalIp(hostname string) (net.IP, error)

	SetIpV4(ip net.IP)
	SetIpV6(ip net.IP)

	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

type HandleRequestModule

type HandleRequestModule interface {
	HandleRequest(result HandleRequestResult) (HandleRequestResult, error)
}

type HandleRequestResult

type HandleRequestResult interface {
	SetRequest(req *http.Request)
	SetDialer(dialer Dialer)
	SetProxy(proxy ProxyFunc)
	SetProxyConnectHeader(header http.Header)
	SetResponse(resp Response)

	GetRequest() *http.Request
	GetDialer() Dialer
	GetProxy() ProxyFunc
	GetProxyConnectHeader() http.Header
	GetResponse() Response
	GetServer() Server

	GetRoundTripper() http.RoundTripper
}

type ListenType

type ListenType byte
const (
	ListenTypeHttp ListenType = iota
	ListenTypeHttps
)

type Module

type Module interface {
	GetDirective() string
	Clone() Module

	conf.Block
}

type ModulesManager

type ModulesManager interface {
	GetModule(directive string, conds ...Condition) Module
	GetModulesForRequest(req *http.Request) []Module
}

type ProxyFunc

type ProxyFunc func(*http.Request) (*url.URL, error)

type RequestHandler

type RequestHandler struct {
	Server Server
}

func NewRequestHandler

func NewRequestHandler(server Server) *RequestHandler

func (*RequestHandler) ServeHTTP

func (t *RequestHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Response

type Response interface {
	Write(rw http.ResponseWriter, result HandleRequestResult) error
	GetCode() int
	GetLAddr() net.Addr
	GetRAddr() net.Addr
}

type ResponseError

type ResponseError struct {
	Code  int
	Error string
}

func NewResponseError

func NewResponseError(code int, error string) *ResponseError

func (*ResponseError) GetCode

func (t *ResponseError) GetCode() int

func (*ResponseError) GetLAddr

func (*ResponseError) GetLAddr() net.Addr

func (*ResponseError) GetRAddr

func (*ResponseError) GetRAddr() net.Addr

func (*ResponseError) Write

type Server

type Server interface {
	GetModulesManager() ModulesManager
	GetListenIp() net.IP
	GetListenPort() int
	GetListenType() ListenType
	GetCertFile() string
	GetKeyFile() string
	GetErrorLog() *log.Logger
	GetDebugLog() *log.Logger
	GetReadTimeout() time.Duration
	GetReadHeaderTimeout() time.Duration
	GetWriteTimeout() time.Duration
	GetIdleTimeout() time.Duration

	SetListenIp(ip string) error
	SetListenPort(port string) error
	SetListenType(typ string) error
	SetCertFile(filename string)
	SetKeyFile(filename string)
	SetErrorLog(filename string) error
	SetDebugLog(filename string) error
	SetReadTimeout(timeout string) error
	SetReadHeaderTimeout(timeout string) error
	SetWriteTimeout(timeout string) error
	SetIdleTimeout(timeout string) error

	LoadConfig(filename string) error
	ListenAndServe() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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