prifma

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 15 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

func NewConfigMain

func NewConfigMain(server Server) conf.Block

func NewConfigModule

func NewConfigModule(server Server) conf.Block

func NewConfigServer

func NewConfigServer(server Server) conf.Block

func NewRequestHandler

func NewRequestHandler(server Server) http.Handler

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)

func NewConditionDstDomain

func NewConditionDstDomain(tester ConditionTester) Condition

func NewConditionHeader

func NewConditionHeader(tester ConditionTester, key string) Condition

func NewConditionSrcIp

func NewConditionSrcIp(tester ConditionTester) Condition

type ConditionDstDomain

type ConditionDstDomain struct {
	Tester ConditionTester
}

func (*ConditionDstDomain) Test

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

type ConditionHeader

type ConditionHeader struct {
	Tester ConditionTester
	Name   string
}

func (*ConditionHeader) Test

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

type ConditionSrcIp

type ConditionSrcIp struct {
	Tester ConditionTester
}

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) (ConditionTester, error)

func NewConditionTesterCIDR

func NewConditionTesterCIDR(val string) (ConditionTester, error)

func NewConditionTesterEquals

func NewConditionTesterEquals(val string) (ConditionTester, error)

func NewConditionTesterRegexp

func NewConditionTesterRegexp(val string) (ConditionTester, error)

type ConditionTesterCIDR

type ConditionTesterCIDR struct {
	Net *net.IPNet
}

func (*ConditionTesterCIDR) Test

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

type ConditionTesterEquals

type ConditionTesterEquals struct {
	Value string
}

func (*ConditionTesterEquals) Test

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

type ConditionTesterRegexp

type ConditionTesterRegexp struct {
	Regexp *regexp.Regexp
}

func (*ConditionTesterRegexp) Test

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

type ConfigMain

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

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 {
	Server Server
	Conds  []Condition
}

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 (*ConfigServer) Call

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

func (*ConfigServer) CallBlock

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

type DefaultDialer

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

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 (*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 (*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
	Config         conf.Block
	Server         http.Server
}

func (*DefaultServer) GetErrorLog

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

func (*DefaultServer) GetIdleTimeout

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

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) SetErrorLog

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

func (*DefaultServer) SetIdleTimeout

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

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)
}

func NewDialer

func NewDialer() Dialer

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
}

func NewHandleRequestResult

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

type ListenType

type ListenType byte
const (
	ListenTypeHttp ListenType = iota
)

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
}

func NewModulesManager

func NewModulesManager(modules ...Module) ModulesManager

type ProxyFunc

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

type RequestHandler

type RequestHandler struct {
	Server Server
}

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
}

func NewResponseError

func NewResponseError(code int, error string) Response

type ResponseError

type ResponseError struct {
	Code  int
	Error string
}

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
	GetErrorLog() *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
	SetErrorLog(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
}

func NewServer

func NewServer(modules ...Module) Server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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