http

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PHttpErr = errors.New("the server requested http, but the request was https")

	PHttpsErr = errors.New("the server requested https, but the request was http")

	PTimeout = errors.New("read client timeout, connect close")
)
View Source
var (
	RouteInfoKey     = "routeInfo"
	RequestInfoKey   = "httpRequestId"
	RequestHttpIdKey = "br_httpId"
	RequestDomainKey = "br_domain"
	ProxyKey         = "httpProxy"
	ForwardedKey     = "X-Forwarded-For"
)

Functions

func AddRouteInfo

func AddRouteInfo(httpId string, domain string, paths []string, fun ProxyConnectionFunction)

AddRouteInfo adds a route to the routes slice

func RouteClean

func RouteClean()

Types

type Conn

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

func (*Conn) Close

func (h *Conn) Close() error

func (*Conn) LocalAddr

func (h *Conn) LocalAddr() net.Addr

func (*Conn) OnData

func (h *Conn) OnData(b []byte)

OnData handles incoming data for the HTTP connection It writes the data to an internal buffer and signals that new data is available

func (*Conn) Read

func (h *Conn) Read(b []byte) (n int, err error)

Read implements the io.Reader interface for HttpConn. It reads data from the connection buffer with proper synchronization and protocol validation.

func (*Conn) RemoteAddr

func (h *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (h *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (h *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (h *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (h *Conn) Write(b []byte) (n int, err error)

type Future

type Future interface {
	Done(data []byte)
	ReqId() int64
	Close()
}

type Proxy

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

func NewHttpProxy

func NewHttpProxy(fun RouteFunction, proxyId string) *Proxy

func (*Proxy) ServeHTTP

func (h *Proxy) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type ProxyConnection

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

func NewProxyConnection

func NewProxyConnection(conn net.Conn,
	tracker *Tracker) *ProxyConnection

func (*ProxyConnection) Close

func (proxy *ProxyConnection) Close() error

func (*ProxyConnection) Read

func (proxy *ProxyConnection) Read(p []byte) (n int, err error)

Read implements the io.Reader interface for ProxyConnection It reads data from the connection, first checking any cached data, then waiting for new data if necessary

func (*ProxyConnection) Write

func (proxy *ProxyConnection) Write(b []byte) (n int, err error)

Write implements the io.Writer interface for ProxyConnection. It encodes the provided byte slice into a tunnel protocol format and writes it to the connection. The encoding method differs based on whether the connection is a WebSocket or regular connection.

type ProxyConnectionFunction

type ProxyConnectionFunction func(httpId string) (workConn net.Conn, err error)

ProxyConnectionFunction is a function that returns a net.Conn

type ResponseFuture

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

func (*ResponseFuture) Close

func (f *ResponseFuture) Close()

func (*ResponseFuture) Done

func (f *ResponseFuture) Done(data []byte)

func (*ResponseFuture) Error

func (f *ResponseFuture) Error(err error)

func (*ResponseFuture) ReqId

func (f *ResponseFuture) ReqId() int64

func (*ResponseFuture) Wait

func (f *ResponseFuture) Wait() ([]byte, error)

func (*ResponseFuture) WaitTimeout

func (f *ResponseFuture) WaitTimeout(d time.Duration) ([]byte, error)

WaitTimeout waits with timeout

type RouteFunction

type RouteFunction func(request *http.Request) (*RouteInfo, error)

RouteFunction is a function that returns a RouteInfo

type RouteInfo

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

RouteInfo is a struct that holds information about a route

func GetRouteInfo

func GetRouteInfo(domain string, path string) *RouteInfo

GetRouteInfo returns the RouteInfo for a given path

type Tracker

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

Tracker HttpTracker httpx tracker

func NewHttpTracker

func NewHttpTracker(channel transport.Channel) *Tracker

func (*Tracker) Close

func (receiver *Tracker) Close(reqId int64)

func (*Tracker) GetFuture

func (receiver *Tracker) GetFuture(reqId int64) (Future, bool)

func (*Tracker) PutRequest

func (receiver *Tracker) PutRequest(future Future)

func (*Tracker) Run

func (receiver *Tracker) Run()

type TunnelHttpServer

type TunnelHttpServer struct {
	*tunnel.BaseTunnelServer
	// contains filtered or unexported fields
}

TunnelHttpServer is a struct that represents a HTTP tunnel server.

func NewHttpTunnelServer

func NewHttpTunnelServer(server *tunnel.BaseTunnelServer) (*TunnelHttpServer, error)

NewHttpTunnelServer is a constructor function for HttpTunnelServer. It takes a pointer to BaseTunnelServer as input and returns a pointer to HttpTunnelServer. The constructor sets the NewDupServer field of BaseTunnelServer to the startAfter method of HttpTunnelServer, which is used to perform cleanup or subsequent processing operations startAfter the server processes the request. The constructor also returns a pointer to HttpTunnelServer.

func (*TunnelHttpServer) Open

func (htl *TunnelHttpServer) Open(ch Channel, tb srv.TraverseBy) error

func (*TunnelHttpServer) OpenWorker

func (htl *TunnelHttpServer) OpenWorker(ch Channel, request *exchange.ClientWorkConnReq) error

func (*TunnelHttpServer) Reader

func (htl *TunnelHttpServer) Reader(ch Channel, tb srv.TraverseBy) error

Reader is a method of HttpTunnelServer, which is used to process incoming requests. It

func (*TunnelHttpServer) RegisterConn

func (htl *TunnelHttpServer) RegisterConn(ch Channel, request exchange.TRegister) (serverId string, err error)

RegisterConn is a method of HttpTunnelServer, which is used to register a connection.

type WebsocketConnection

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

func (*WebsocketConnection) Close

func (wc *WebsocketConnection) Close() error

func (*WebsocketConnection) Read

func (wc *WebsocketConnection) Read(p []byte) (n int, err error)

func (*WebsocketConnection) Write

func (wc *WebsocketConnection) Write(b []byte) (n int, err error)

type WebsocketProxy

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

func NewWebsocketProxy

func NewWebsocketProxy(route func(req *http.Request) (*RouteInfo, error)) *WebsocketProxy

func (*WebsocketProxy) ServeHTTP

func (h *WebsocketProxy) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type WsFuture

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

func (*WsFuture) Close

func (f *WsFuture) Close()

func (*WsFuture) Done

func (f *WsFuture) Done(data []byte)

func (*WsFuture) Read

func (f *WsFuture) Read(bytes []byte) (int, error)

func (*WsFuture) ReqId

func (f *WsFuture) ReqId() int64

Jump to

Keyboard shortcuts

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