Initial import

This commit is contained in:
2025-09-26 08:49:53 +02:00
commit a76650da35
35 changed files with 4660 additions and 0 deletions

88
proxy/config.go Normal file
View File

@@ -0,0 +1,88 @@
package proxy
import (
"net"
"net/http"
"time"
"git.maze.io/maze/styx/proxy/policy"
"git.maze.io/maze/styx/proxy/resolver"
)
type ConnectHandler interface {
HandleConnect(session *Session, network, address string) net.Conn
}
// ConnectHandlerFunc is called when the proxy receives a new HTTP CONNECT request.
type ConnectHandlerFunc func(session *Session, network, address string) net.Conn
func (f ConnectHandlerFunc) HandleConnect(session *Session, network, address string) net.Conn {
return f(session, network, address)
}
type RequestHandler interface {
HandleRequest(session *Session) (*http.Request, *http.Response)
}
// RequestHandlerFunc is called when the proxy receives a new request.
type RequestHandlerFunc func(session *Session) (*http.Request, *http.Response)
func (f RequestHandlerFunc) HandleRequest(session *Session) (*http.Request, *http.Response) {
return f(session)
}
type ResponseHandler interface {
HandleResponse(session *Session) *http.Response
}
// ResponseHandler is called when the proxy receives a response.
type ResponseHandlerFunc func(session *Session) *http.Response
func (f ResponseHandlerFunc) HandleResponse(session *Session) *http.Response {
return f(session)
}
type ErrorHandler interface {
HandleError(session *Session, err error)
}
type ErrorHandlerFunc func(session *Session, err error)
func (f ErrorHandlerFunc) HandleError(session *Session, err error) {
f(session, err)
}
type Config struct {
// Listen address.
Listen string `hcl:"listen,optional"`
// Bind address for outgoing connections.
Bind string `hcl:"bind,optional"`
// Interface for outgoing connections.
Interface string `hcl:"interface,optional"`
// Upstream proxy servers.
Upstream []string `hcl:"upstream,optional"`
// DialTimeout for establishing new connections.
DialTimeout time.Duration `hcl:"dial_timeout,optional"`
// Policy for the proxy.
Policy *policy.Policy `hcl:"policy,block"`
// Resolver for the proxy.
Resolver resolver.Resolver
ConnectHandler ConnectHandler
RequestHandler RequestHandler
ResponseHandler ResponseHandler
ErrorHandler ErrorHandler
}
var (
_ ConnectHandler = (ConnectHandlerFunc)(nil)
_ RequestHandler = (RequestHandlerFunc)(nil)
_ ResponseHandler = (ResponseHandlerFunc)(nil)
_ ErrorHandler = (ErrorHandlerFunc)(nil)
)