transport

package
v0.0.0-...-6656868 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package transport provides the HTTP transport abstraction layer used by all injection testing flows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomUserAgent

func RandomUserAgent() string

RandomUserAgent returns a randomly selected User-Agent string from the built-in list.

Types

type Client

type Client interface {
	// Do sends an HTTP request and returns the response.
	Do(ctx context.Context, req *Request) (*Response, error)

	// SetProxy configures an HTTP/SOCKS5 proxy for all subsequent requests.
	SetProxy(proxyURL string) error

	// SetRateLimit sets the maximum requests per second.
	SetRateLimit(rps float64)

	// Stats returns transport statistics.
	Stats() *TransportStats
}

Client is the interface for the HTTP transport layer. All injection testing flows go through this interface.

type ClientOptions

type ClientOptions struct {
	// Timeout is the default timeout for all requests.
	Timeout time.Duration

	// ProxyURL is the proxy URL (HTTP or SOCKS5).
	ProxyURL string

	// FollowRedirects controls whether redirects are followed.
	FollowRedirects bool

	// InsecureSkipVerify disables TLS certificate verification.
	InsecureSkipVerify bool

	// RandomUserAgent enables random User-Agent header selection.
	RandomUserAgent bool

	// MaxRPS is the maximum requests per second (0 = unlimited).
	MaxRPS float64
}

ClientOptions holds configuration for creating a new DefaultClient.

type DefaultClient

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

DefaultClient is the default implementation of the Client interface, backed by net/http.

func NewClient

func NewClient(opts ClientOptions) (*DefaultClient, error)

NewClient creates a new DefaultClient with the given options.

func (*DefaultClient) Do

func (c *DefaultClient) Do(ctx context.Context, req *Request) (*Response, error)

Do sends an HTTP request and returns the response. It applies rate limiting, timing measurement, custom headers, cookies, and optional per-request overrides.

func (*DefaultClient) SetProxy

func (c *DefaultClient) SetProxy(proxyURL string) error

SetProxy configures an HTTP or SOCKS5 proxy for subsequent requests.

func (*DefaultClient) SetRateLimit

func (c *DefaultClient) SetRateLimit(rps float64)

SetRateLimit sets the maximum number of requests per second. A value of 0 or less disables rate limiting.

func (*DefaultClient) Stats

func (c *DefaultClient) Stats() *TransportStats

Stats returns aggregate transport statistics.

type Request

type Request struct {
	// Method is the HTTP method (GET, POST, PUT, etc.).
	Method string

	// URL is the target URL.
	URL string

	// Headers contains custom HTTP headers to include.
	Headers map[string]string

	// Body is the request body content.
	Body string

	// ContentType is the Content-Type header value.
	ContentType string

	// Cookies contains cookies to include in the request.
	Cookies map[string]string

	// FollowRedirects overrides the client-level redirect setting
	// for this specific request. nil means use the client default.
	FollowRedirects *bool

	// Timeout overrides the client-level timeout for this specific
	// request. Zero means use the client default.
	Timeout time.Duration
}

Request represents an HTTP request to be sent by the transport client.

func (*Request) Clone

func (r *Request) Clone() *Request

Clone returns a deep copy of the Request.

type Response

type Response struct {
	// StatusCode is the HTTP status code.
	StatusCode int

	// Headers contains the response headers.
	Headers http.Header

	// Body is the raw response body.
	Body []byte

	// ContentLength is the content length from the response header.
	ContentLength int64

	// Duration is the precise round-trip time for the request.
	Duration time.Duration

	// URL is the final URL after any redirects.
	URL string

	// Protocol is the protocol version (e.g., "HTTP/1.1", "HTTP/2.0").
	Protocol string
}

Response represents an HTTP response received from the transport client.

func (*Response) BodyString

func (r *Response) BodyString() string

BodyString returns the response body as a string.

type TransportStats

type TransportStats struct {
	TotalRequests int64
	TotalDuration time.Duration
	AvgDuration   time.Duration
}

TransportStats holds aggregate statistics for the transport client.

Jump to

Keyboard shortcuts

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