goproxy

package
v0.0.0-...-e9f0680 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package goproxy HTTP(S)代理, 支持中间人代理解密HTTPS数据

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneHeader

func CloneHeader(h http.Header, h2 http.Header)

CloneHeader 深拷贝Header

func CopyHeader

func CopyHeader(dst, src http.Header)

CopyHeader 浅拷贝Header

Types

type ConnBuffer

type ConnBuffer struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewConnBuffer

func NewConnBuffer(conn net.Conn, buf *bufio.ReadWriter) *ConnBuffer

func (*ConnBuffer) BufferReader

func (cb *ConnBuffer) BufferReader() *bufio.Reader

func (*ConnBuffer) Header

func (cb *ConnBuffer) Header() http.Header

func (*ConnBuffer) Hijack

func (cb *ConnBuffer) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*ConnBuffer) Peek

func (cb *ConnBuffer) Peek(n int) ([]byte, error)

func (*ConnBuffer) Read

func (cb *ConnBuffer) Read(b []byte) (n int, err error)

func (*ConnBuffer) Write

func (cb *ConnBuffer) Write(p []byte) (n int, err error)

func (*ConnBuffer) WriteHeader

func (cb *ConnBuffer) WriteHeader(_ int)

type Context

type Context struct {
	Req         *http.Request
	Data        map[interface{}]interface{}
	TunnelProxy bool

	Resp *http.Response
	// contains filtered or unexported fields
}

Context 代理上下文

func (*Context) Abort

func (c *Context) Abort()

Abort 中断执行

func (*Context) Addr

func (c *Context) Addr() string

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted 是否已中断执行

func (*Context) IsFailFast

func (c *Context) IsFailFast()

func (*Context) IsHTTPS

func (c *Context) IsHTTPS() bool

func (*Context) IsNeedMock

func (c *Context) IsNeedMock()

func (*Context) Reset

func (c *Context) Reset(req *http.Request)

Reset 重置

type DefaultDelegate

type DefaultDelegate struct {
	Delegate
}

DefaultDelegate 默认Handler什么也不做

func (*DefaultDelegate) Auth

func (h *DefaultDelegate) Auth(ctx *Context, rw http.ResponseWriter)

func (*DefaultDelegate) BeforeRequest

func (h *DefaultDelegate) BeforeRequest(ctx *Context)

func (*DefaultDelegate) BeforeResponse

func (h *DefaultDelegate) BeforeResponse(ctx *Context, resp *http.Response, err error)

func (*DefaultDelegate) Connect

func (h *DefaultDelegate) Connect(ctx *Context, rw http.ResponseWriter)

func (*DefaultDelegate) ErrorLog

func (h *DefaultDelegate) ErrorLog(err error)

func (*DefaultDelegate) Finish

func (h *DefaultDelegate) Finish(ctx *Context)

func (*DefaultDelegate) ParentProxy

func (h *DefaultDelegate) ParentProxy(req *http.Request) (*url.URL, error)

type Delegate

type Delegate interface {
	// Connect 收到客户端连接
	Connect(ctx *Context, rw http.ResponseWriter)
	// Auth 代理身份认证
	Auth(ctx *Context, rw http.ResponseWriter)
	// BeforeRequest HTTP请求前 设置X-Forwarded-For, 修改Header、Body
	BeforeRequest(ctx *Context)
	// BeforeResponse 响应发送到客户端前, 修改Header、Body、Status Code
	BeforeResponse(ctx *Context, resp *http.Response, err error)
	// ParentProxy 上级代理
	ParentProxy(*http.Request) (*url.URL, error)
	// Finish 本次请求结束
	Finish(ctx *Context)
	// ErrorLog 记录错误信息
	ErrorLog(err error)
}

type DialContext

type DialContext func(ctx context.Context, network, addr string) (net.Conn, error)

type HeaderPool

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

func NewHeaderPool

func NewHeaderPool() *HeaderPool

func (*HeaderPool) Get

func (p *HeaderPool) Get() http.Header

func (*HeaderPool) Put

func (p *HeaderPool) Put(header http.Header)

type Option

type Option func(*options)

func WithClientTrace

func WithClientTrace(t *httptrace.ClientTrace) Option

func WithDecryptHTTPS

func WithDecryptHTTPS(c cert.Cache) Option

WithDecryptHTTPS 中间人代理, 解密HTTPS, 需实现证书缓存接口

func WithDelegate

func WithDelegate(delegate Delegate) Option

WithDelegate 设置委托类

func WithDisableKeepAlive

func WithDisableKeepAlive(disableKeepAlive bool) Option

WithDisableKeepAlive 连接是否重用

func WithTransport

func WithTransport(t *http.Transport) Option

WithTransport 自定义http transport

type Proxy

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

Proxy 实现了http.Handler接口

func New

func New(opt ...Option) *Proxy

New 创建proxy实例

func (*Proxy) ClientConnNum

func (p *Proxy) ClientConnNum() int32

ClientConnNum get client connection number

func (*Proxy) DoRequest

func (p *Proxy) DoRequest(ctx *Context, responseFunc func(*http.Response, error))

DoRequest

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP 实现了http.Handler接口

type RequestPool

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

func (*RequestPool) Get

func (p *RequestPool) Get() *http.Request

func (*RequestPool) Put

func (p *RequestPool) Put(req *http.Request)

Directories

Path Synopsis
Package cert HTTPS证书
Package cert HTTPS证书

Jump to

Keyboard shortcuts

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