stdhttpclient

package
v0.0.0-...-528926c Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Driver is a high-performance HTTP client driver that implements the httpclient.Driver interface. It uses the standard library's http.Client with optimizations for high throughput scenarios. This driver is optimized for maximum performance with minimal allocations and persistent connections.

func NewDriver

func NewDriver() *Driver

NewDriver creates a new Driver with a high-performance HTTP client. The client is optimized for high throughput with: - Persistent connections and connection pooling - Aggressive keepalive settings - Optimized timeouts for low latency - Large connection pool limits

func NewDriverWithConfig

func NewDriverWithConfig(config PerformanceConfig) *Driver

NewDriverWithConfig creates a new Driver with custom performance configuration.

func NewDriverWithHTTPClient

func NewDriverWithHTTPClient(client *http.Client) *Driver

NewDriverWithHTTPClient creates a new Driver with the specified HTTP client. This allows for custom HTTP client configurations, such as timeouts or transport settings. The driver is initialized with object pools for optimal performance.

func NewExtremePerformanceDriver

func NewExtremePerformanceDriver() *Driver

NewExtremePerformanceDriver creates a driver optimized for extreme throughput.

func NewHighPerformanceDriver

func NewHighPerformanceDriver() *Driver

NewHighPerformanceDriver creates a new Driver with maximum performance settings. This function provides the most aggressive optimization for high-throughput scenarios.

func (*Driver) Close

func (d *Driver) Close()

Close releases resources held by the driver. It closes the HTTP client and clears the object pools. This should be called when the driver is no longer needed to prevent resource leaks. It is safe to call this multiple times.

func (*Driver) Do

Do sends the HTTP request and returns the response. It uses object pooling to minimize allocations and improve performance.

func (*Driver) Request

func (d *Driver) Request(method, url string, body io.Reader) (httpclient.Request, error)

Request creates a new HTTP request with the specified method, URL, and body. It uses object pooling to minimize allocations and improve performance.

type PerformanceConfig

type PerformanceConfig struct {
	// Connection pool settings
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConnsPerHost     int

	// Timeout settings
	IdleConnTimeout       time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
	ExpectContinueTimeout time.Duration
	RequestTimeout        time.Duration

	// Performance settings
	DisableCompression bool
	ForceAttemptHTTP2  bool
	DisableKeepAlives  bool
}

PerformanceConfig holds configuration for high-performance HTTP client settings.

func DefaultPerformanceConfig

func DefaultPerformanceConfig() PerformanceConfig

DefaultPerformanceConfig returns default high-performance configuration.

func ExtremePerformanceConfig

func ExtremePerformanceConfig() PerformanceConfig

ExtremePerformanceConfig returns configuration optimized for maximum throughput. Use this configuration when you need to send thousands of requests per second.

type Request

type Request struct {
	HTTP *http.Request
	// contains filtered or unexported fields
}

Request is a high-performance wrapper around http.Request that implements the httpclient.Request interface. It provides methods to set headers and access the underlying HTTP request. The request uses object pooling to minimize allocations.

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string)

SetHeader sets a header for the HTTP request.

type Response

type Response struct {
	HTTP *http.Response
	// contains filtered or unexported fields
}

Response is a high-performance wrapper around http.Response that implements the httpclient.Response interface. It provides methods to access the response status code, body, and to close the response body. The response uses object pooling to minimize allocations.

func (*Response) Body

func (r *Response) Body() io.Reader

Body returns the body of the HTTP response as an io.Reader. If the response is nil, it returns nil.

func (*Response) Close

func (r *Response) Close() error

Close closes the response body and returns objects to the pool for reuse. This method should always be called when the response is no longer needed to prevent memory leaks and to return pooled objects for reuse.

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns the HTTP status code of the response. If the response is nil, it returns 0.

Jump to

Keyboard shortcuts

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