transport

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnection represents connection-level errors
	ErrConnection = errors.New("connection error")

	// ErrTLS represents TLS/SSL related errors
	ErrTLS = errors.New("TLS error")

	// ErrDNS represents DNS resolution errors
	ErrDNS = errors.New("DNS error")

	// ErrTimeout represents timeout errors
	ErrTimeout = errors.New("timeout error")

	// ErrProxy represents proxy-related errors
	ErrProxy = errors.New("proxy error")

	// ErrProtocol represents protocol negotiation errors
	ErrProtocol = errors.New("protocol error")

	// ErrRequest represents request-level errors
	ErrRequest = errors.New("request error")

	// ErrResponse represents response-level errors
	ErrResponse = errors.New("response error")

	// ErrClosed represents errors when transport is closed
	ErrClosed = errors.New("transport closed")
)

Error categories for better error handling

Functions

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError checks if an error is a connection error

func IsDNSError

func IsDNSError(err error) bool

IsDNSError checks if an error is a DNS error

func IsProxyError

func IsProxyError(err error) bool

IsProxyError checks if an error is a proxy error

func IsTLSError

func IsTLSError(err error) bool

IsTLSError checks if an error is a TLS error

func IsTimeout

func IsTimeout(err error) bool

IsTimeout checks if an error is a timeout error

func WrapError

func WrapError(op, host, port, protocol string, cause error) error

WrapError wraps an error with transport context

Types

type ConnStats

type ConnStats struct {
	Host           string
	CreatedAt      time.Time
	LastUsedAt     time.Time
	UseCount       int64
	Age            time.Duration
	IdleTime       time.Duration
	IsReused       bool
	SessionResumed bool   // True if TLS session was resumed
	TLSVersion     uint16 // TLS version (e.g., 0x0304 for TLS 1.3)
	CipherSuite    uint16 // Negotiated cipher suite
}

ConnStats contains connection statistics

type HTTP1ConnStats

type HTTP1ConnStats struct {
	IdleConns      int
	TotalUseCount  int64
	OldestCreated  time.Time
	NewestLastUsed time.Time
}

HTTP1ConnStats contains HTTP/1.1 connection statistics

type HTTP1Transport

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

HTTP1Transport is a custom HTTP/1.1 transport with uTLS fingerprinting and connection pooling with keep-alive support

func NewHTTP1Transport

func NewHTTP1Transport(preset *fingerprint.Preset, dnsCache *dns.Cache) *HTTP1Transport

NewHTTP1Transport creates a new HTTP/1.1 transport with uTLS

func NewHTTP1TransportWithProxy

func NewHTTP1TransportWithProxy(preset *fingerprint.Preset, dnsCache *dns.Cache, proxy *ProxyConfig) *HTTP1Transport

NewHTTP1TransportWithProxy creates a new HTTP/1.1 transport with optional proxy

func (*HTTP1Transport) Close

func (t *HTTP1Transport) Close()

Close shuts down the transport

func (*HTTP1Transport) GetDNSCache

func (t *HTTP1Transport) GetDNSCache() *dns.Cache

GetDNSCache returns the DNS cache

func (*HTTP1Transport) RoundTrip

func (t *HTTP1Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

func (*HTTP1Transport) SetInsecureSkipVerify

func (t *HTTP1Transport) SetInsecureSkipVerify(skip bool)

SetInsecureSkipVerify sets whether to skip TLS verification

func (*HTTP1Transport) Stats

func (t *HTTP1Transport) Stats() map[string]HTTP1ConnStats

Stats returns transport statistics

type HTTP2Transport

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

HTTP2Transport is a custom HTTP/2 transport with uTLS fingerprinting and proper connection reuse

func NewHTTP2Transport

func NewHTTP2Transport(preset *fingerprint.Preset, dnsCache *dns.Cache) *HTTP2Transport

NewHTTP2Transport creates a new HTTP/2 transport with uTLS

func NewHTTP2TransportWithProxy

func NewHTTP2TransportWithProxy(preset *fingerprint.Preset, dnsCache *dns.Cache, proxy *ProxyConfig) *HTTP2Transport

NewHTTP2TransportWithProxy creates a new HTTP/2 transport with optional proxy support

func (*HTTP2Transport) Close

func (t *HTTP2Transport) Close()

Close shuts down the transport

func (*HTTP2Transport) GetConnectionUseCount

func (t *HTTP2Transport) GetConnectionUseCount(host, port string) int64

GetConnectionUseCount returns how many times a connection has been used

func (*HTTP2Transport) GetDNSCache

func (t *HTTP2Transport) GetDNSCache() *dns.Cache

GetDNSCache returns the DNS cache

func (*HTTP2Transport) IsConnectionReused

func (t *HTTP2Transport) IsConnectionReused(host, port string) bool

IsConnectionReused checks if the connection for a host will be reused Returns true if a usable connection already exists in the pool

func (*HTTP2Transport) RoundTrip

func (t *HTTP2Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

func (*HTTP2Transport) Stats

func (t *HTTP2Transport) Stats() map[string]ConnStats

Stats returns transport statistics

type HTTP3Stats

type HTTP3Stats struct {
	RequestCount int64
	DialCount    int64 // Number of new connections created
	Reusing      bool  // True if connections are being reused
}

HTTP3Stats contains HTTP/3 transport statistics

type HTTP3Transport

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

HTTP3Transport is an HTTP/3 transport with proper QUIC connection reuse http3.Transport handles connection pooling internally - we just provide DNS resolution

func NewHTTP3Transport

func NewHTTP3Transport(preset *fingerprint.Preset, dnsCache *dns.Cache) *HTTP3Transport

NewHTTP3Transport creates a new HTTP/3 transport

func (*HTTP3Transport) Close

func (t *HTTP3Transport) Close() error

Close shuts down the transport and all connections

func (*HTTP3Transport) GetDNSCache

func (t *HTTP3Transport) GetDNSCache() *dns.Cache

GetDNSCache returns the DNS cache

func (*HTTP3Transport) GetDialCount

func (t *HTTP3Transport) GetDialCount() int64

GetDialCount returns the number of new connections created

func (*HTTP3Transport) GetRequestCount

func (t *HTTP3Transport) GetRequestCount() int64

GetRequestCount returns the total number of requests made

func (*HTTP3Transport) IsConnectionReused

func (t *HTTP3Transport) IsConnectionReused(host string) bool

IsConnectionReused returns true if requests > dials (meaning reuse happened)

func (*HTTP3Transport) RoundTrip

func (t *HTTP3Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

func (*HTTP3Transport) Stats

func (t *HTTP3Transport) Stats() HTTP3Stats

Stats returns transport statistics

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Body       []byte
	Headers    map[string]string
}

HTTPError represents an HTTP-level error (4xx, 5xx responses)

func NewHTTPError

func NewHTTPError(statusCode int, status string, body []byte, headers map[string]string) *HTTPError

NewHTTPError creates an HTTP error from status code

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error implements the error interface

func (*HTTPError) IsClientError

func (e *HTTPError) IsClientError() bool

IsClientError returns true for 4xx errors

func (*HTTPError) IsRetryable

func (e *HTTPError) IsRetryable() bool

IsRetryable returns true for errors that should be retried

func (*HTTPError) IsServerError

func (e *HTTPError) IsServerError() bool

IsServerError returns true for 5xx errors

type Protocol

type Protocol int

Protocol represents the HTTP protocol version

const (
	// ProtocolAuto automatically selects the best protocol (H3 -> H2 -> H1)
	ProtocolAuto Protocol = iota
	// ProtocolHTTP1 forces HTTP/1.1 over TCP
	ProtocolHTTP1
	// ProtocolHTTP2 forces HTTP/2 over TCP
	ProtocolHTTP2
	// ProtocolHTTP3 forces HTTP/3 over QUIC
	ProtocolHTTP3
)

func (Protocol) String

func (p Protocol) String() string

String returns the string representation of the protocol

type ProxyConfig

type ProxyConfig struct {
	URL      string // Proxy URL (e.g., "http://proxy:8080" or "http://user:pass@proxy:8080")
	Username string // Proxy username (optional, can also be in URL)
	Password string // Proxy password (optional, can also be in URL)
}

ProxyConfig contains proxy server configuration

type Request

type Request struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    []byte
	Timeout time.Duration
}

Request represents an HTTP request

type Response

type Response struct {
	StatusCode int
	Headers    map[string]string
	Body       []byte
	FinalURL   string
	Timing     *protocol.Timing
	Protocol   string // "h1", "h2", or "h3"
}

Response represents an HTTP response

type Transport

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

Transport is a unified HTTP transport supporting HTTP/1.1, HTTP/2, and HTTP/3

func NewTransport

func NewTransport(presetName string) *Transport

NewTransport creates a new unified transport

func NewTransportWithProxy

func NewTransportWithProxy(presetName string, proxy *ProxyConfig) *Transport

NewTransportWithProxy creates a new unified transport with optional proxy

func (*Transport) ClearProtocolCache

func (t *Transport) ClearProtocolCache()

ClearProtocolCache clears the learned protocol support cache

func (*Transport) Close

func (t *Transport) Close()

Close shuts down the transport

func (*Transport) Do

func (t *Transport) Do(ctx context.Context, req *Request) (*Response, error)

Do executes an HTTP request

func (*Transport) GetDNSCache

func (t *Transport) GetDNSCache() *dns.Cache

GetDNSCache returns the DNS cache

func (*Transport) SetInsecureSkipVerify

func (t *Transport) SetInsecureSkipVerify(skip bool)

SetInsecureSkipVerify sets whether to skip TLS certificate verification

func (*Transport) SetPreset

func (t *Transport) SetPreset(presetName string)

SetPreset changes the fingerprint preset

func (*Transport) SetProtocol

func (t *Transport) SetProtocol(p Protocol)

SetProtocol sets the preferred protocol

func (*Transport) SetProxy

func (t *Transport) SetProxy(proxy *ProxyConfig)

SetProxy sets or updates the proxy configuration Note: This recreates the underlying transports

func (*Transport) SetTimeout

func (t *Transport) SetTimeout(timeout time.Duration)

SetTimeout sets the request timeout

func (*Transport) Stats

func (t *Transport) Stats() map[string]interface{}

Stats returns transport statistics

type TransportError

type TransportError struct {
	Op        string // Operation that failed (e.g., "dial", "tls_handshake", "request")
	Host      string // Target host
	Port      string // Target port
	Protocol  string // Protocol (h1, h2, h3)
	Cause     error  // Underlying error
	Category  error  // Error category (ErrConnection, ErrTLS, etc.)
	Retryable bool   // Whether the operation can be retried
}

TransportError provides detailed error information

func NewConnectionError

func NewConnectionError(op, host, port, protocol string, cause error) *TransportError

NewConnectionError creates a connection error

func NewDNSError

func NewDNSError(host string, cause error) *TransportError

NewDNSError creates a DNS error

func NewProtocolError

func NewProtocolError(host, port, protocol string, cause error) *TransportError

NewProtocolError creates a protocol negotiation error

func NewProxyError

func NewProxyError(op, host, port string, cause error) *TransportError

NewProxyError creates a proxy error

func NewRequestError

func NewRequestError(op, host, port, protocol string, cause error) *TransportError

NewRequestError creates a request error

func NewTLSError

func NewTLSError(op, host, port, protocol string, cause error) *TransportError

NewTLSError creates a TLS error

func NewTimeoutError

func NewTimeoutError(op, host, port, protocol string, cause error) *TransportError

NewTimeoutError creates a timeout error

func (*TransportError) Error

func (e *TransportError) Error() string

Error implements the error interface

func (*TransportError) Is

func (e *TransportError) Is(target error) bool

Is checks if the error matches the target

func (*TransportError) IsRetryable

func (e *TransportError) IsRetryable() bool

IsRetryable returns whether the error is retryable

func (*TransportError) Unwrap

func (e *TransportError) Unwrap() error

Unwrap returns the underlying error

Jump to

Keyboard shortcuts

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