httpproxy

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 44 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBind = errors.New("http proxy")

ErrBind wraps the error of a listener that could not be opened; that failure was logged already.

Functions

func LoadFallback404

func LoadFallback404(path string) []byte

LoadFallback404 returns the body of fallback_404_file, the built-in one if path is empty or unreadable.

func LogCertLoaded

func LogCertLoaded(route, domain, file string, cert *tls.Certificate)

LogCertLoaded reports that cert is in use for route; domain and file are left out when empty.

Types

type AccessRecord

type AccessRecord struct {
	Time      time.Time // when the request arrived
	Route     string    // the domain of the host entry, or "http"/"https" when none matched
	Host      int       // the host entry id, 0 when none matched
	SrcIP     string
	Method    string
	Domain    string // the Host header
	Path      string
	Query     string // the raw query, without "?"
	Proto     string // such as HTTP/1.1
	Status    int    // 0 when the connection was dropped without a response
	Bytes     int64  // of the response body
	Duration  time.Duration
	Target    string // the backend host:port, empty when none was dialed
	Referer   string
	UserAgent string
}

AccessRecord is one request to the domain proxy, given to HttpProxy.AccessLog when the request ends, refused ones included.

type Http3Server

type Http3Server struct {
	*HttpsServer
	// contains filtered or unexported fields
}

func NewHttp3Server

func NewHttp3Server(httpsSrv *HttpsServer, udpConn net.PacketConn) *Http3Server

func (*Http3Server) Close

func (s *Http3Server) Close() error

Close stops the server. Closing the socket ends the QUIC transport and its connections, so the workers return.

func (*Http3Server) GetConfigForClient

func (s *Http3Server) GetConfigForClient(info *tls.ClientHelloInfo) (*tls.Config, error)

func (*Http3Server) HandleQUIC

func (s *Http3Server) HandleQUIC(qc *quic.Conn, alpn, sni string)

func (*Http3Server) Start

func (s *Http3Server) Start() error

type HttpProxy

type HttpProxy struct {
	*proxy.BaseServer

	HttpServer  *HttpServer
	HttpsServer *HttpsServer
	Http3Server *Http3Server
	HttpPort    int
	HttpsPort   int
	Http3Port   int

	HttpOnlyPass          string
	HttpPortStr           string
	HttpsPortStr          string
	Http3PortStr          string
	TimeLimitErrorContent []byte
	FlowLimitErrorContent []byte
	// Fallback404Content is the body of the 404 a bridge connection gets
	// for a host of no route (fallback_404_file).
	Fallback404Content []byte
	Magic              *certmagic.Config

	Acme                  *certmagic.ACMEIssuer
	ResponseHeaderTimeout time.Duration
	AddOrigin             bool
	Http3Bridge           bool
	ErrorAlways           bool
	ForceAutoSsl          bool
	// AccessLog, if set, is called with every request that ends, whatever
	// the log level; set it before Start.
	AccessLog func(AccessRecord)
	// contains filtered or unexported fields
}

func NewHttpProxy

func NewHttpProxy(store Store, bridge proxy.NetBridge, task *model.Tunnel, httpPort, httpsPort, http3Port int, httpOnlyPass string, addOrigin, allowLocalProxy bool, plans *Plans) *HttpProxy

func (*HttpProxy) Close

func (s *HttpProxy) Close() error

func (*HttpProxy) FallbackCert

func (s *HttpProxy) FallbackCert(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

FallbackCert returns the certificate for the TLS of a bridge connection that asks for hello.ServerName, chosen as the domain proxy chooses for a visitor of that name, or nil, nil when the name matches no route and the caller's default certificate applies.

func (*HttpProxy) ServeFallback

func (s *HttpProxy) ServeFallback(c net.Conn, state *tls.ConnectionState) bool

ServeFallback serves c through the domain proxy, every byte of the HTTP request still unread. state is the TLS c arrived over, nil for none: only HTTP/1.1 is possible, as no ALPN was negotiated for it. It returns false, leaving c to the caller, when the proxy has no HTTP engine or is closed.

func (*HttpProxy) ServeHTTP3

func (s *HttpProxy) ServeHTTP3(qc *quic.Conn, wrap func(http.Handler) http.Handler) bool

ServeHTTP3 serves qc as HTTP/3 through the domain proxy until qc ends, wrap wrapping its handler. It returns false when the proxy has no HTTP engine.

func (*HttpProxy) Start

func (s *HttpProxy) Start() error

type HttpServer

type HttpServer struct {
	*HttpProxy
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(httpProxy *HttpProxy, l net.Listener) *HttpServer

func (*HttpServer) Close

func (s *HttpServer) Close() error

func (*HttpServer) DialContext

func (s *HttpServer) DialContext(ctx context.Context, _, _ string) (net.Conn, error)

DialContext opens the backend connection of a regular request, whose proxyRequest ctx carries.

func (*HttpServer) DialTlsContext

func (s *HttpServer) DialTlsContext(ctx context.Context, network, addr string) (net.Conn, error)

func (*HttpServer) NewServer

func (s *HttpServer) NewServer(port int, scheme string) *http.Server

func (*HttpServer) Start

func (s *HttpServer) Start() error

type HttpsListener

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

HttpsListener wraps a parent listener and hands out connections whose TLS handshake has already completed.

func NewHttpsListener

func NewHttpsListener(l net.Listener) *HttpsListener

func (*HttpsListener) Accept

func (l *HttpsListener) Accept() (net.Conn, error)

func (*HttpsListener) Addr

func (l *HttpsListener) Addr() net.Addr

func (*HttpsListener) Close

func (l *HttpsListener) Close() error

type HttpsServer

type HttpsServer struct {
	*HttpServer
	// contains filtered or unexported fields
}

func NewHttpsServer

func NewHttpsServer(httpServer *HttpServer, l net.Listener) *HttpsServer

func (*HttpsServer) Close

func (s *HttpsServer) Close() error

func (*HttpsServer) Start

func (s *HttpsServer) Start() error

type NotFound

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

NotFound answers every request of the connections handed to it with the 404 of an unknown site: the fallback of a node that runs no domain proxy.

func NewNotFound

func NewNotFound(body []byte) *NotFound

NewNotFound returns a NotFound that answers with body.

func (*NotFound) Close

func (n *NotFound) Close() error

Close stops serving.

func (*NotFound) ServeFallback

func (n *NotFound) ServeFallback(c net.Conn, state *tls.ConnectionState) bool

ServeFallback serves c, every byte of its request unread; it returns false once closed.

type Plans

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

Plans holds the compiled plan of each host. The server drops the plan of a host whenever the host is edited or deleted.

func NewPlans

func NewPlans() *Plans

func (*Plans) Clear

func (c *Plans) Clear()

Clear drops every plan.

func (*Plans) Remove

func (c *Plans) Remove(id int)

Remove drops the plan of host id and closes its idle backend connections.

type Store

type Store interface {
	// GetInfoByHost finds the host entry that serves request r for host.
	GetInfoByHost(host string, r *http.Request) (*model.Host, error)
	// FindCertByHost finds the host entry whose certificate serves name.
	FindCertByHost(name string) (*model.Host, error)
	// RangeClientCertHosts calls fn for the hosts of client clientID that
	// carry a certificate, until fn returns false.
	RangeClientCertHosts(clientID int, fn func(*model.Host) bool)
}

Store is what the host proxy reads of the stored hosts.

Jump to

Keyboard shortcuts

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