xrequest

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomString

func RandomString() string

RandomString generates a pseudo-random alphanumeric string based on the current Unix timestamp in nanoseconds and a random uint64 value, both encoded in base36. It guarantees a safe [string] construction without slice panic risks.

func SanitizeCookieName

func SanitizeCookieName(n string) string

SanitizeCookieName cleans up a cookie name by replacing newline (\n) and carriage return (\r) characters with hyphens. It returns the sanitized [string].

func SanitizeCookieValue

func SanitizeCookieValue(v string, quoted bool) string

SanitizeCookieValue validates and cleans a cookie value based on allowed bytes. If the value contains spaces or commas, or if the quoted [bool] parameter is true, the resulting [string] will be wrapped in double quotes.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth holds credentials for HTTP Basic Authentication.

type ClientOption

type ClientOption func(*clientOptions)

ClientOption defines the configuration function type for request options.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the default base URL for the client.

func WithCookieJar

func WithCookieJar(jar http.CookieJar) ClientOption

WithCookieJar sets the cookie jar implementation.

func WithFollowRedirects

func WithFollowRedirects(followRedirects bool, maxRedirects int) ClientOption

WithFollowRedirects configures redirect behavior.

func WithProxy

func WithProxy(proxy string) ClientOption

WithProxy sets the proxy URL string.

func WithTLSClientConfig

func WithTLSClientConfig(config *tls.Config) ClientOption

WithTLSClientConfig sets SSL/TLS client options.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout duration for requests.

func WithTransport

func WithTransport(transport http.RoundTripper) ClientOption

WithTransport sets a custom http.RoundTripper.

type HTTPClient

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

HTTPClient represents the HTTP client wrapper around the standard net/http client.

func NewHTTPClient

func NewHTTPClient(options ...ClientOption) *HTTPClient

NewHTTPClient instantiates a new HTTP client based strictly on standard library implementations.

func (*HTTPClient) Close

func (c *HTTPClient) Close() error

Close closes idle connections on the underlying transport.

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(url string, options *Options) (*Response, error)

Delete sends a DELETE request.

func (*HTTPClient) Get

func (c *HTTPClient) Get(url string, options *Options) (*Response, error)

Get sends a GET request.

func (*HTTPClient) Head

func (c *HTTPClient) Head(url string, options *Options) (*Response, error)

Head sends a HEAD request.

func (*HTTPClient) Options

func (c *HTTPClient) Options(url string, options *Options) (*Response, error)

Options sends an OPTIONS request.

func (*HTTPClient) Patch

func (c *HTTPClient) Patch(url string, options *Options) (*Response, error)

Patch sends a PATCH request.

func (*HTTPClient) Post

func (c *HTTPClient) Post(url string, options *Options) (*Response, error)

Post sends a POST request.

func (*HTTPClient) Put

func (c *HTTPClient) Put(url string, options *Options) (*Response, error)

Put sends a PUT request.

func (*HTTPClient) Request

func (c *HTTPClient) Request(ctx context.Context, method, targetURL string, options *Options) (*Response, error)

Request triggers an HTTP request based on method, target URL, and contextual options.

type Multipart

type Multipart struct {
	FileName    string
	ContentType string
	io.Reader
}

Multipart represents a multipart form field metadata and stream.

type Options

type Options struct {
	Headers     http.Header
	BasicAuth   *BasicAuth
	BearerToken string
	Cookies     []*http.Cookie
	Query       url.Values
	Body        any
	JSON        any
	Form        map[string]string
	Multipart   map[string]*Multipart
}

Options contains parameters applied to an individual request.

type Response

type Response struct {
	*http.Response
}

Response wraps the standard http.Response to add utility methods.

func (*Response) Err

func (r *Response) Err() error

func (*Response) Ok

func (r *Response) Ok() bool

Ok returns true if the status code is between 200 and 299.

type Transport

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

Transport implements an HTTP transport that supports standard HTTP/HTTPS configurations and custom Alt-Svc tracking features using standard libraries.

func NewTransport

func NewTransport(tlsClientConfig *tls.Config) *Transport

NewTransport creates a new Transport instance.

func (*Transport) Close

func (t *Transport) Close() error

Close closes idle connections on the standard transport.

func (*Transport) RoundTrip

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

RoundTrip executes a single HTTP transaction.

Jump to

Keyboard shortcuts

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