Documentation
¶
Overview ¶
Package fast provides high-performance fasthttp engine adapters for aoni.Request and aoni.Response.
Index ¶
- Variables
- func NewStdClient(c *Client) *http.Client
- type Client
- func (c *Client) Config() aoni.Config
- func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (c *Client) DialPlainForWS(ctx context.Context, addr string) (net.Conn, error)
- func (c *Client) DialTLSContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (c *Client) DialTLSForWS(ctx context.Context, addr string) (net.Conn, error)
- func (c *Client) Do(req aoni.Request) (aoni.Response, error)
- func (c *Client) Engine() *fasthttp.Client
- func (c *Client) Request(ctx context.Context, method, path string, mods ...aoni.RequestModifier) (aoni.Response, error)
- func (c *Client) With(opts ...aoni.ClientOption) *Client
- type HTTPDoer
- type PooledResponse
- type Request
- func (f *Request) AddHeader(key, value string)
- func (f *Request) AddHeaderBytes(key, value []byte)
- func (f *Request) AddQueryParam(key, value string)
- func (f *Request) AddQueryParamBytes(key, value []byte)
- func (f *Request) BodyBytes() []byte
- func (f *Request) BodyStream() io.Reader
- func (f *Request) Context() context.Context
- func (f *Request) DelHeader(key string)
- func (f *Request) DelHeaderBytes(key []byte)
- func (f *Request) EngineRequest() any
- func (f *Request) FastHTTPRequest() *fasthttp.Request
- func (f *Request) GetBody() (io.ReadCloser, error)
- func (f *Request) HTTPRequest() *http.Request
- func (f *Request) Header(key string) string
- func (f *Request) HeaderBytes(key []byte) []byte
- func (f *Request) Method() string
- func (f *Request) Path() string
- func (f *Request) RawQuery() string
- func (f *Request) Release()
- func (f *Request) ResetHeaders()
- func (f *Request) SetBodyBytes(body []byte)
- func (f *Request) SetBodyStream(r io.Reader, contentLength int64)
- func (f *Request) SetContext(ctx context.Context)
- func (f *Request) SetGetBody(fn func() (io.ReadCloser, error))
- func (f *Request) SetHeader(key, value string)
- func (f *Request) SetHeaderBytes(key, value []byte)
- func (f *Request) SetMethod(method string)
- func (f *Request) SetMethodBytes(method []byte)
- func (f *Request) SetPath(path string)
- func (f *Request) SetQueryParam(key, value string)
- func (f *Request) SetQueryParamBytes(key, value []byte)
- func (f *Request) SetRawQuery(query string)
- func (f *Request) SetRawQueryBytes(query []byte)
- func (f *Request) SetURIBytes(uri []byte)
- func (f *Request) SetURL(urlStr string)
- func (f *Request) URL() string
- type Response
- func (f *Response) BodyBytes() []byte
- func (f *Response) BodyStream() io.ReadCloser
- func (f *Response) Close() error
- func (f *Response) EngineResponse() any
- func (f *Response) FastHTTPResponse() *fasthttp.Response
- func (f *Response) HTTPResponse() *http.Response
- func (f *Response) Header(key string) string
- func (f *Response) HeaderBytes(key []byte) []byte
- func (f *Response) Headers() map[string][]string
- func (f *Response) Release()
- func (f *Response) SetTrailers(trailers map[string][]string)
- func (f *Response) SetUncompressed(v bool)
- func (f *Response) Status() string
- func (f *Response) StatusBytes() []byte
- func (f *Response) StatusCode() int
- func (f *Response) Trailers() map[string][]string
- func (f *Response) Uncompressed() bool
- func (f *Response) UnsafeBodyBytes() []byte
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilURL indicates an attempt to dispatch an HTTP request without a destination address. ErrNilURL = errors.New("fast: request URL is nil") // ErrTargetURLEmpty is returned when no target URL is provided for request execution. ErrTargetURLEmpty = errors.New("fast: target URL is empty") // ErrUTLSHandshakeFailed is returned when uTLS negotiation fails over a fasthttp socket. ErrUTLSHandshakeFailed = errors.New("fast: uTLS handshake failed") // ErrProxyConnectionFailed is returned when establishing an outbound proxy tunnel fails. ErrProxyConnectionFailed = errors.New("fast: proxy connection failed") // ErrMaxRedirectsExceeded is returned when the request halts because the maximum redirect threshold was reached. ErrMaxRedirectsExceeded = errors.New("fast: maximum redirects limit exceeded") // ErrCannotRewind is returned when a stream request body cannot be rewound for a 307/308 redirect. ErrCannotRewind = errors.New("fast: cannot rewind request body stream for redirect") // ErrHedgingFailed is returned when all hedged request attempts fail to execute. ErrHedgingFailed = errors.New("fast: all hedged request attempts failed") // ErrNothingWritten indicates a network error occurred before any request bytes reached the socket. ErrNothingWritten = errors.New("fast: connection closed before any request bytes were written") )
Functions ¶
func NewStdClient ¶
NewStdClient adapts a fast Client into a standard *http.Client.
Bridges fasthttp with standard library HTTP abstractions.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client executes ultra-high-performance HTTP requests over fasthttp, seamlessly multiplexing native H1 (fasthttp), native H2 (h2engine), and native H3 (h3engine).
func NewClient ¶
func NewClient(opts ...aoni.ClientOption) *Client
NewClient creates a new multiprotocol Client configured with fasthttp, uTLS, native HTTP/2 framing, and native HTTP/3 QUIC support.
func (*Client) DialContext ¶
DialContext establishes a raw L4 connection applying active proxy, DNS, and anti-DPI configurations.
func (*Client) DialPlainForWS ¶
DialPlainForWS satisfies aoni.WSDialer by establishing a plain TCP socket for WebSocket upgrades.
func (*Client) DialTLSContext ¶
DialTLSContext establishes an encrypted TLS socket connection using uTLS ClientHello specifications.
func (*Client) DialTLSForWS ¶
DialTLSForWS satisfies aoni.WSDialer by establishing an encrypted TLS connection for WebSocket upgrades.
func (*Client) Do ¶
Do executes a prepared aoni.Request contract, routing through the target native protocol engine (H1, H2, or H3).
func (*Client) Engine ¶
Engine returns the underlying *fasthttp.Client engine instance.
func (*Client) Request ¶
func (c *Client) Request( ctx context.Context, method, path string, mods ...aoni.RequestModifier, ) (aoni.Response, error)
Request executes an HTTP request across HTTP/1.1, native HTTP/2, or native HTTP/3. Handles redirects, cookies, proxy failover, hedging, response validation, WAF challenges, and telemetry.
Postconditions:
- The returned aoni.Response MUST be closed via aoni.Response.Close to return objects back to sync.Pool.
- Aborts execution immediately if ctx is canceled without memory race hazards.
type PooledResponse ¶
type PooledResponse struct {
*Response
// contains filtered or unexported fields
}
PooledResponse wraps a fasthttp response and returns instances back to sync.Pool upon Close.
func NewPooledResponse ¶
func NewPooledResponse(fastReq *fasthttp.Request, fastResp *fasthttp.Response) *PooledResponse
NewPooledResponse acquires a pooled PooledResponse adapter wrapping fastReq and fastResp. The caller is responsible for releasing the request and response objects.
func (*PooledResponse) Close ¶
func (r *PooledResponse) Close() error
Close releases underlying fasthttp objects and returns PooledResponse to memory pool.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request adapts a high-performance *fasthttp.Request to the unified aoni.Request contract.
func NewRequest ¶
NewRequest acquires a pooled Request adapter wrapping req. The caller is responsible for releasing the request object.
func (*Request) AddHeaderBytes ¶
AddHeaderBytes appends value to header key using byte slices.
func (*Request) AddQueryParam ¶
AddQueryParam appends a key-value query parameter to the URI.
func (*Request) AddQueryParamBytes ¶
AddQueryParamBytes appends a key-value query parameter using byte slices.
func (*Request) BodyBytes ¶
BodyBytes yields direct access to internal fasthttp request body byte slice.
func (*Request) BodyStream ¶
BodyStream yields an io.Reader for the request body.
func (*Request) DelHeaderBytes ¶
DelHeaderBytes removes header key using a byte slice.
func (*Request) EngineRequest ¶
EngineRequest yields the underlying *fasthttp.Request cast to any.
func (*Request) FastHTTPRequest ¶
FastHTTPRequest yields the underlying *fasthttp.Request instance.
func (*Request) GetBody ¶
func (f *Request) GetBody() (io.ReadCloser, error)
GetBody generates a fresh ReadCloser for replaying the request payload stream.
func (*Request) HTTPRequest ¶
HTTPRequest yields nil for fasthttp request adapters.
func (*Request) HeaderBytes ¶
HeaderBytes yields direct access to internal header buffer bytes.
func (*Request) Release ¶
func (f *Request) Release()
Release returns the Request adapter back to the pool.
func (*Request) ResetHeaders ¶
func (f *Request) ResetHeaders()
ResetHeaders removes all headers from the request.
func (*Request) SetBodyBytes ¶
SetBodyBytes sets request body to a raw byte slice.
func (*Request) SetBodyStream ¶
SetBodyStream assigns a streaming reader as request body and sets up rewind capabilities if supported.
func (*Request) SetContext ¶
SetContext assigns the execution context to the request adapter.
func (*Request) SetGetBody ¶
func (f *Request) SetGetBody(fn func() (io.ReadCloser, error))
SetGetBody assigns a custom generator for rewinding body streams during retries and 307/308 redirects.
func (*Request) SetHeaderBytes ¶
SetHeaderBytes sets header key to value using byte slices.
func (*Request) SetMethodBytes ¶
SetMethodBytes assigns the HTTP method from a byte slice without allocations.
func (*Request) SetQueryParam ¶
SetQueryParam sets or replaces a query parameter in the URI.
func (*Request) SetQueryParamBytes ¶
SetQueryParamBytes sets or replaces a query parameter using byte slices.
func (*Request) SetRawQuery ¶
SetRawQuery assigns the raw query string.
func (*Request) SetRawQueryBytes ¶
SetRawQueryBytes assigns the raw query string from a byte slice.
func (*Request) SetURIBytes ¶
SetURIBytes assigns the destination address from a byte slice.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response adapts a high-performance *fasthttp.Response to the unified aoni.Response contract.
func NewResponse ¶
NewResponse wraps resp into a unified aoni.Response adapter. The caller is responsible for releasing the response object.
func (*Response) BodyBytes ¶
BodyBytes returns an independent, memory-safe copy of the response body bytes.
Postconditions:
- The returned slice is safe to retain or mutate beyond response pool recycling.
func (*Response) BodyStream ¶
func (f *Response) BodyStream() io.ReadCloser
BodyStream yields an io.ReadCloser wrapping the response body stream or bytes.
func (*Response) Close ¶
Close releases resources bound to the response wrapper and slurps unread stream bytes to preserve sockets.
func (*Response) EngineResponse ¶
EngineResponse yields the underlying *fasthttp.Response cast to any.
func (*Response) FastHTTPResponse ¶
FastHTTPResponse yields the underlying *fasthttp.Response instance.
func (*Response) HTTPResponse ¶
HTTPResponse yields nil for fasthttp response adapters.
func (*Response) HeaderBytes ¶
HeaderBytes yields direct access to header value byte slice inside internal buffers.
func (*Response) Release ¶
func (f *Response) Release()
Release returns the Response adapter back to memory pool.
func (*Response) SetTrailers ¶
SetTrailers registers HTTP trailers captured during frame execution.
func (*Response) SetUncompressed ¶
SetUncompressed records whether the response payload was transparently decompressed by the client.
func (*Response) StatusBytes ¶
StatusBytes yields status text as a byte slice.
func (*Response) StatusCode ¶
StatusCode yields the HTTP status code.
func (*Response) Uncompressed ¶
Uncompressed reports whether the response body was transparently decompressed by the client.
func (*Response) UnsafeBodyBytes ¶
UnsafeBodyBytes provides zero-allocation direct access to internal response buffers.
Warning:
- Points directly to volatile internal buffers managed by sync.Pool.
- MUST NOT be referenced, mutated, or retained after closing or recycling the response.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport adapts a fast Client to satisfy the standard http.RoundTripper contract.
func NewTransport ¶
NewTransport constructs an http.RoundTripper adapter backed by a fast Client.