addon

package
v0.0.0-...-7e01349 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	proxy.BaseAddon
}

func (*Decoder) Response

func (d *Decoder) Response(f *proxy.Flow)

type Dumper

type Dumper struct {
	proxy.BaseAddon
	// contains filtered or unexported fields
}

func NewDumper

func NewDumper(out io.Writer, level int) *Dumper

func NewDumperWithFilename

func NewDumperWithFilename(filename string, level int) *Dumper

func (*Dumper) RequestError

func (d *Dumper) RequestError(f *proxy.Flow, err error)

func (*Dumper) Requestheaders

func (d *Dumper) Requestheaders(f *proxy.Flow)

func (*Dumper) Response

func (d *Dumper) Response(f *proxy.Flow)

type FlowContext

type FlowContext struct {
	*proxy.Flow
	Params map[string]string
	// contains filtered or unexported fields
}

FlowContext wraps proxy.Flow with a gin-like handler chain and path params.

func (*FlowContext) Abort

func (c *FlowContext) Abort()

Abort stops the handler chain.

func (*FlowContext) IsAborted

func (c *FlowContext) IsAborted() bool

IsAborted returns whether Abort has been called.

func (*FlowContext) Next

func (c *FlowContext) Next()

Next executes the next handler in the chain.

func (*FlowContext) Param

func (c *FlowContext) Param(key string) string

Param returns the named path parameter (e.g. ":id").

type FlowGroup

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

FlowGroup is a set of routes sharing a host filter, path prefix, and middleware.

func (*FlowGroup) ANY

func (g *FlowGroup) ANY(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) DELETE

func (g *FlowGroup) DELETE(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) GET

func (g *FlowGroup) GET(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) Group

func (g *FlowGroup) Group(prefix string, handlers ...FlowHandlerFunc) *FlowGroup

Group creates a nested sub-group inheriting the parent's host and middleware.

func (*FlowGroup) HEAD

func (g *FlowGroup) HEAD(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) PATCH

func (g *FlowGroup) PATCH(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) POST

func (g *FlowGroup) POST(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) PUT

func (g *FlowGroup) PUT(path string, handlers ...FlowHandlerFunc)

func (*FlowGroup) Use

func (g *FlowGroup) Use(handlers ...FlowHandlerFunc) *FlowGroup

Use adds middleware to this group. Returns a new FlowGroup to avoid mutating siblings.

type FlowHandlerFunc

type FlowHandlerFunc func(*FlowContext)

FlowHandlerFunc is the handler signature, similar to gin.HandlerFunc.

type FlowRouter

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

FlowRouter dispatches proxy flows to handlers by host/method/path pattern, similar to gin's Router. An empty host matches any host.

Pattern syntax:

  • :name matches a single path/host segment, captured as Param("name")
  • *name matches the rest of the path, captured as Param("name")
  • * wildcard in host, matches a single label (e.g. "*.example.com")

func NewFlowRouter

func NewFlowRouter() *FlowRouter

func (*FlowRouter) ANY

func (r *FlowRouter) ANY(path string, handlers ...FlowHandlerFunc)

ANY registers all common HTTP methods for the given path on any host.

func (*FlowRouter) DELETE

func (r *FlowRouter) DELETE(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) GET

func (r *FlowRouter) GET(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) Group

func (r *FlowRouter) Group(prefix string, handlers ...FlowHandlerFunc) *FlowGroup

Group creates a route group with a shared path prefix and optional middleware.

func (*FlowRouter) HEAD

func (r *FlowRouter) HEAD(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) HandleFlow

func (r *FlowRouter) HandleFlow(f *proxy.Flow)

HandleFlow matches the flow against registered routes and executes the handler chain.

func (*FlowRouter) Host

func (r *FlowRouter) Host(host string) *FlowGroup

Host returns a FlowGroup scoped to the given host pattern.

router.Host("api.example.com").GET("/users", handler)
router.Host("*.example.com").ANY("/", handler)

func (*FlowRouter) PATCH

func (r *FlowRouter) PATCH(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) POST

func (r *FlowRouter) POST(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) PUT

func (r *FlowRouter) PUT(path string, handlers ...FlowHandlerFunc)

func (*FlowRouter) Use

func (r *FlowRouter) Use(handlers ...FlowHandlerFunc)

Use registers global middleware executed for every flow regardless of route match.

type MapLocal

type MapLocal struct {
	proxy.BaseAddon
	Items  []*mapLocalItem
	Enable bool
}

func NewMapLocalFromFile

func NewMapLocalFromFile(filename string) (*MapLocal, error)

func (*MapLocal) Requestheaders

func (ml *MapLocal) Requestheaders(f *proxy.Flow)

type MapRemote

type MapRemote struct {
	proxy.BaseAddon
	Items  []*mapRemoteItem
	Enable bool
}

func NewMapRemoteFromFile

func NewMapRemoteFromFile(filename string) (*MapRemote, error)

func (*MapRemote) Requestheaders

func (mr *MapRemote) Requestheaders(f *proxy.Flow)

type RouterAddon

type RouterAddon struct {
	proxy.BaseAddon
	// contains filtered or unexported fields
}

RouterAddon integrates FlowRouter into the proxy addon system. Each hook stage that carries a *Flow and a meaningful URL has its own router, giving callers gin-like routing for every phase of the HTTP/WebSocket/SSE lifecycle.

Routable stages (receive *Flow with URL + method):

OnRequestHeaders  → Requestheaders  – headers received, body not yet read
OnRequest         → Request         – full request body available
OnResponseHeaders → Responseheaders – response headers received, body not yet read
OnResponse        → Response        – full response body available
OnWebSocket       → WebSocketMessage – each WebSocket frame
OnSSE             → SSEMessage       – each Server-Sent Event

Non-routable stages (no URL or non-Flow signature) are left to the caller via proxy.BaseAddon embedding: ClientConnected/Disconnected, ServerConnected/Disconnected, TlsEstablishedServer, StreamRequestModifier, StreamResponseModifier, AccessProxyServer.

func NewRouterAddon

func NewRouterAddon() *RouterAddon

func (*RouterAddon) OnRequest

func (a *RouterAddon) OnRequest() *FlowRouter

OnRequest returns the router for the Request hook. Full request body is available.

func (*RouterAddon) OnRequestHeaders

func (a *RouterAddon) OnRequestHeaders() *FlowRouter

OnRequestHeaders returns the router for the Requestheaders hook. Headers are available; body has not been read yet.

func (*RouterAddon) OnResponse

func (a *RouterAddon) OnResponse() *FlowRouter

OnResponse returns the router for the Response hook. Full response body is available.

func (*RouterAddon) OnResponseHeaders

func (a *RouterAddon) OnResponseHeaders() *FlowRouter

OnResponseHeaders returns the router for the Responseheaders hook. Response headers are available; body has not been read yet.

func (*RouterAddon) OnSSE

func (a *RouterAddon) OnSSE() *FlowRouter

OnSSE returns the router for the SSEMessage hook. Fired for each Server-Sent Event; routes by the original request URL.

func (*RouterAddon) OnWebSocket

func (a *RouterAddon) OnWebSocket() *FlowRouter

OnWebSocket returns the router for the WebSocketMessage hook. Fired for each WebSocket frame; routes by the original upgrade request URL.

func (*RouterAddon) Request

func (a *RouterAddon) Request(f *proxy.Flow)

func (*RouterAddon) Requestheaders

func (a *RouterAddon) Requestheaders(f *proxy.Flow)

func (*RouterAddon) Response

func (a *RouterAddon) Response(f *proxy.Flow)

func (*RouterAddon) Responseheaders

func (a *RouterAddon) Responseheaders(f *proxy.Flow)

func (*RouterAddon) SSEMessage

func (a *RouterAddon) SSEMessage(f *proxy.Flow)

func (*RouterAddon) WebSocketMessage

func (a *RouterAddon) WebSocketMessage(f *proxy.Flow)

type StripProxyHeadersAddon

type StripProxyHeadersAddon struct {
	proxy.BaseAddon
	// contains filtered or unexported fields
}

StripProxyHeadersAddon removes HTTP headers that reveal the presence of a proxy (Via, X-Forwarded-For, Proxy-Connection, etc.) from every outbound request. This is a common requirement when building MITM proxies that must appear transparent to the upstream server.

By default, the addon strips a well-known set of headers. Callers can customise this set via WithExtraStripHeaders (add more) or WithStripHeaders (replace entirely).

Example:

p.AddAddon(addon.NewStripProxyHeadersAddon())

Or with extra custom headers:

p.AddAddon(

addon.NewStripProxyHeadersAddon(
    addon.WithExtraStripHeaders("X-Custom-Debug", "X-Internal-ID"),
),

)

func NewStripProxyHeadersAddon

func NewStripProxyHeadersAddon(opts ...StripProxyHeadersOption) *StripProxyHeadersAddon

NewStripProxyHeadersAddon creates a new StripProxyHeadersAddon. Without options it strips the default set of proxy-revealing headers.

func (*StripProxyHeadersAddon) Requestheaders

func (a *StripProxyHeadersAddon) Requestheaders(f *proxy.Flow)

Requestheaders strips configured headers from every request before it is forwarded to the upstream server.

type StripProxyHeadersOption

type StripProxyHeadersOption func(*StripProxyHeadersAddon)

StripProxyHeadersOption configures a StripProxyHeadersAddon.

func WithExtraStripHeaders

func WithExtraStripHeaders(headers ...string) StripProxyHeadersOption

WithExtraStripHeaders appends additional header names to the default list.

func WithStripHeaders

func WithStripHeaders(headers ...string) StripProxyHeadersOption

WithStripHeaders replaces the entire default header list with the given set.

type TLSHandshakeInfo

type TLSHandshakeInfo struct {
	// ServerName 是本次握手的 SNI,通常等于目标域名。
	ServerName string

	// NegotiatedProtocol 是 ALPN 协商结果,例如 "h2" 或 "http/1.1"。
	// 为空表示服务端未通过 ALPN 选择协议。
	NegotiatedProtocol string

	// TLSVersion 是协商的 TLS 版本号(例如 tls.VersionTLS13 = 0x0304)。
	TLSVersion uint16

	// CipherSuite 是协商的密码套件 ID(例如 tls.TLS_AES_128_GCM_SHA256)。
	// 可用 tls.CipherSuiteName(info.CipherSuite) 获取可读名称。
	CipherSuite uint16

	// DidResume 为 true 表示本次握手复用了之前的 TLS Session(session ticket)。
	DidResume bool
}

TLSHandshakeInfo 包含一次出站 TLS 握手完成后的可观测字段。 所有字段来自 *tls.ConnectionState,与底层实现(crypto/tls 或 uTLS)无关。

type TLSInspectorAddon

type TLSInspectorAddon struct {
	proxy.BaseAddon
	// contains filtered or unexported fields
}

TLSInspectorAddon 在每次出站 TLS 握手完成后触发回调。 零值可用(回调为 nil 时仅以 DEBUG 级别打日志)。 通过 NewTLSInspectorAddon 构造更推荐。

func NewTLSInspectorAddon

func NewTLSInspectorAddon(fn func(TLSHandshakeInfo)) *TLSInspectorAddon

NewTLSInspectorAddon 创建一个握手结果检查 addon。

fn  每次握手完成后被调用,参数为本次握手信息。传 nil 退化为内置 DEBUG 日志。

func (*TLSInspectorAddon) TlsEstablishedServer

func (a *TLSInspectorAddon) TlsEstablishedServer(connCtx *proxy.ConnContext)

TlsEstablishedServer 实现 proxy.Addon 接口,在出站 TLS 握手完成时被代理调用。

Jump to

Keyboard shortcuts

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