proxylib

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 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

Overview

Package proxylib parses proxy lists in any practical format and turns entries into usable dialers/URLs.

Supported protocols: http, https, socks4, socks4a, socks5, socks5h.

Accepted input formats (mixed freely, separated by newlines, commas or semicolons; a JSON array of strings is accepted too):

http://user:pass@host:8080      https://host:443
socks5://host:1080              socks5h://user:pass@host
socks4://host:1080              socks4a://host:1080
user:pass@host:8080             host:8080
host:8080:user:pass             host                 (http, port 80)
[::1]:8080                      [::1]:8080:user:pass

Rules:

  • scheme defaults to http when omitted (port defaults: http 80, https 443, socks* 1080);
  • path/query/fragment on scheme URLs are stripped (new-api compat);
  • IPv6 literals must be bracketed;
  • lines starting with '#' are comments and skipped;
  • duplicate entries are removed (first occurrence wins);
  • credentials are never exposed: String() masks the password and the package never logs raw proxy strings.

Index

Constants

View Source
const (
	SchemeHTTP    = "http"
	SchemeHTTPS   = "https"
	SchemeSOCKS4  = "socks4"
	SchemeSOCKS4a = "socks4a"
	SchemeSOCKS5  = "socks5"
	SchemeSOCKS5h = "socks5h"
)

Schemes the parser accepts.

Variables

This section is empty.

Functions

func Mask

func Mask(raw string) string

Mask masks credentials of a raw proxy string (any accepted format). Used by the control plane for display; unknown formats pass through.

func ParseList

func ParseList(raw string) ([]Entry, []LineError)

ParseList parses a raw multi-entry list and reports per-line errors. The valid entries are still returned so callers can preview partial results.

Types

type Entry

type Entry struct {
	Scheme string
	Host   string
	Port   int
	User   string
	Pass   string
}

Entry is a single normalized proxy.

func Parse

func Parse(raw string) ([]Entry, error)

Parse parses a raw multi-entry list strictly: any invalid entry fails the whole list (with the offending lines in the error message).

func ParseEntry

func ParseEntry(token string) (Entry, error)

ParseEntry parses a single proxy token in any supported format.

func (Entry) DialContext

func (e Entry) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext returns a dial function that connects to address through the proxy. For socks variants the connection is a raw tunnel; for http/https proxies use URL() with http.Transport.Proxy instead.

socks5 resolves the destination locally; socks5h, socks4a and socks4 send the hostname to the proxy (remote DNS; socks4 sends an IP — for socks4 the hostname is resolved locally, like socks5).

func (Entry) IsHTTP

func (e Entry) IsHTTP() bool

IsHTTP reports whether the entry is an http/https proxy (used through http.Transport.Proxy).

func (Entry) IsSOCKS

func (e Entry) IsSOCKS() bool

IsSOCKS reports whether the entry is any socks variant.

func (Entry) Key

func (e Entry) Key() string

Key returns the identity used for de-duplication. The password is part of the identity: rotating-session providers (bpproxy, oxylabs, …) encode the session id in the password, so two entries with the same user/host/port but different passwords are different proxies.

func (Entry) String

func (e Entry) String() string

String returns a masked, log-safe representation: credentials are shown as user:****@host:port.

func (Entry) URL

func (e Entry) URL() *url.URL

URL returns the proxy URL for http.Transport.Proxy. Credentials are included; callers must never log the result.

type LineError

type LineError struct {
	Line   int    // 1-based line number in the raw input
	Text   string // original (trimmed) text of the failing entry
	Reason string // human-readable reason
}

LineError reports a single invalid line/entry inside a list.

func (LineError) Error

func (e LineError) Error() string

type ListError

type ListError struct {
	Errors []LineError
}

ListError aggregates line errors. It implements error so strict callers (config validation) can reject the whole list with one message.

func (*ListError) Error

func (e *ListError) Error() string

Jump to

Keyboard shortcuts

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