proxy

package
v0.0.0-...-eefbc77 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RotationKeyPrefix is the prefix for proxy rotation keys in Redis.
	RotationKeyPrefix = "proxy_rotation"
	// LastSuccessKeyPrefix is the prefix for storing last successful proxy index per endpoint.
	LastSuccessKeyPrefix = "proxy_last_success"
	// UnhealthyKeyPrefix is the prefix for storing unhealthy proxy status.
	UnhealthyKeyPrefix = "proxy_unhealthy"
)

Variables

View Source
var (
	// NumericIDPattern matches any sequence of digits for path normalization.
	NumericIDPattern = regexp.MustCompile(`^\d+$`)
	// CDNHashPattern matches the hash portion of CDN URLs.
	CDNHashPattern = regexp.MustCompile(`30DAY-Avatar-[0-9A-F]{32}-Png`)
)

Functions

func GetNormalizedPath

func GetNormalizedPath(path string) string

GetNormalizedPath returns a normalized path where numeric IDs and CDN hashes are replaced with placeholders.

Types

type EndpointPattern

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

EndpointPattern is a regex pattern for an endpoint.

type Middleware

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

Middleware manages proxy rotation and endpoint-specific rate limiting for HTTP requests.

func New

func New(proxies []*url.URL, client rueidis.Client, cfg *config.CommonConfig, requestTimeout time.Duration) *Middleware

New creates a new Middleware instance.

func (*Middleware) Cleanup

func (m *Middleware) Cleanup()

Cleanup closes idle connections in the transport pool.

func (*Middleware) GetProxies

func (m *Middleware) GetProxies() []*url.URL

GetProxies returns the list of proxies.

func (*Middleware) Process

func (m *Middleware) Process(
	ctx context.Context, httpClient *http.Client, req *http.Request, next middleware.NextFunc,
) (*http.Response, error)

Process applies proxy logic before passing the request to the next middleware.

func (*Middleware) SetLogger

func (m *Middleware) SetLogger(l logger.Logger)

SetLogger sets the logger for the middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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