Documentation
¶
Index ¶
- Variables
- func CloseDefaultClient() error
- func FormatBytes(bytes int64) string
- func FormatSpeed(bytesPerSecond float64) string
- func NewCookieJar() (http.CookieJar, error)
- func SetDefaultClient(client Client) error
- func ValidateConfig(cfg *Config) error
- type Client
- type Config
- type DomainClient
- func (dc *DomainClient) ClearCookies()
- func (dc *DomainClient) ClearHeaders()
- func (dc *DomainClient) Close() error
- func (dc *DomainClient) Delete(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) DeleteCookie(name string)
- func (dc *DomainClient) DeleteHeader(key string)
- func (dc *DomainClient) Get(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) GetCookie(name string) *http.Cookie
- func (dc *DomainClient) GetCookies() []*http.Cookie
- func (dc *DomainClient) GetHeaders() map[string]string
- func (dc *DomainClient) Head(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) Options(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) Patch(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) Post(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) Put(path string, options ...RequestOption) (*Result, error)
- func (dc *DomainClient) SetCookie(cookie *http.Cookie) error
- func (dc *DomainClient) SetCookies(cookies []*http.Cookie) error
- func (dc *DomainClient) SetHeader(key, value string) error
- func (dc *DomainClient) SetHeaders(headers map[string]string) error
- type DownloadOptions
- type DownloadProgressCallback
- type DownloadResult
- type FileData
- type FormData
- type HTTPError
- type Request
- type RequestInfo
- type RequestMeta
- type RequestOption
- func WithAccept(accept string) RequestOption
- func WithBasicAuth(username, password string) RequestOption
- func WithBearerToken(token string) RequestOption
- func WithBinary(data []byte, contentType ...string) RequestOption
- func WithBody(body any) RequestOption
- func WithContentType(contentType string) RequestOption
- func WithContext(ctx context.Context) RequestOption
- func WithCookie(cookie http.Cookie) RequestOption
- func WithCookieString(cookieString string) RequestOption
- func WithCookieValue(name, value string) RequestOption
- func WithCookies(cookies []http.Cookie) RequestOption
- func WithFile(fieldName, filename string, content []byte) RequestOption
- func WithFollowRedirects(follow bool) RequestOption
- func WithForm(data map[string]string) RequestOption
- func WithFormData(data *FormData) RequestOption
- func WithHeader(key, value string) RequestOption
- func WithHeaderMap(headers map[string]string) RequestOption
- func WithJSON(data any) RequestOption
- func WithJSONAccept() RequestOption
- func WithMaxRedirects(maxRedirects int) RequestOption
- func WithMaxRetries(maxRetries int) RequestOption
- func WithQuery(key string, value any) RequestOption
- func WithQueryMap(params map[string]any) RequestOption
- func WithText(content string) RequestOption
- func WithTimeout(timeout time.Duration) RequestOption
- func WithUserAgent(userAgent string) RequestOption
- func WithXML(data any) RequestOption
- func WithXMLAccept() RequestOption
- type Response
- func (r *Response) GetCookie(name string) *http.Cookie
- func (r *Response) GetRequestCookie(name string) *http.Cookie
- func (r *Response) GetRequestCookies() []*http.Cookie
- func (r *Response) HasCookie(name string) bool
- func (r *Response) HasRequestCookie(name string) bool
- func (r *Response) Html() string
- func (r *Response) IsClientError() bool
- func (r *Response) IsRedirect() bool
- func (r *Response) IsServerError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) JSON(v any) error
- func (r *Response) String() string
- type ResponseInfo
- type Result
- func Delete(url string, options ...RequestOption) (*Result, error)
- func Get(url string, options ...RequestOption) (*Result, error)
- func Head(url string, options ...RequestOption) (*Result, error)
- func Options(url string, options ...RequestOption) (*Result, error)
- func Patch(url string, options ...RequestOption) (*Result, error)
- func Post(url string, options ...RequestOption) (*Result, error)
- func Put(url string, options ...RequestOption) (*Result, error)
- func (r *Result) Body() string
- func (r *Result) GetCookie(name string) *http.Cookie
- func (r *Result) GetRequestCookie(name string) *http.Cookie
- func (r *Result) HasCookie(name string) bool
- func (r *Result) HasRequestCookie(name string) bool
- func (r *Result) Html() string
- func (r *Result) IsClientError() bool
- func (r *Result) IsRedirect() bool
- func (r *Result) IsServerError() bool
- func (r *Result) IsSuccess() bool
- func (r *Result) JSON(v any) error
- func (r *Result) RawBody() []byte
- func (r *Result) RequestCookies() []*http.Cookie
- func (r *Result) ResponseCookies() []*http.Cookie
- func (r *Result) SaveToFile(filePath string) error
- func (r *Result) StatusCode() int
- func (r *Result) String() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClientClosed is returned when attempting to use a closed client. // This occurs after calling Close() on a client instance. ErrClientClosed = errors.New("client is closed") // ErrNilConfig is returned when a nil configuration is provided. // Always provide a valid Config or use DefaultConfig(). ErrNilConfig = errors.New("config cannot be nil") // ErrInvalidURL is returned when URL validation fails. // URLs must have a valid scheme (http/https) and host. ErrInvalidURL = errors.New("invalid URL") // ErrInvalidHeader is returned when header validation fails. // Headers must not contain control characters or exceed size limits. ErrInvalidHeader = errors.New("invalid header") // ErrInvalidTimeout is returned when timeout is negative or exceeds limits. // Timeout must be between 0 and 30 minutes. ErrInvalidTimeout = errors.New("invalid timeout") // ErrInvalidRetry is returned when retry configuration is invalid. // MaxRetries must be 0-10, BackoffFactor must be 1.0-10.0. ErrInvalidRetry = errors.New("invalid retry configuration") // ErrEmptyFilePath is returned when file path is empty. // Provide a valid file path for download operations. ErrEmptyFilePath = errors.New("file path cannot be empty") // ErrFileExists is returned when file already exists and Overwrite is false. // Set Overwrite=true or ResumeDownload=true in DownloadOptions. ErrFileExists = errors.New("file already exists") // ErrResponseBodyEmpty is returned when attempting to parse empty response body. // Check response.RawBody before calling JSON() or other parsing methods. ErrResponseBodyEmpty = errors.New("response body is empty") // ErrResponseBodyTooLarge is returned when response body exceeds size limit. // Increase MaxResponseBodySize in Config or reduce response size. ErrResponseBodyTooLarge = errors.New("response body too large") )
Functions ¶
func CloseDefaultClient ¶
func CloseDefaultClient() error
CloseDefaultClient closes the default client and resets it. After calling this, the next package-level function call will create a new client. This function is safe for concurrent use.
func FormatBytes ¶
FormatBytes formats bytes in human-readable format (e.g., "1.50 KB", "2.00 MB").
func FormatSpeed ¶
FormatSpeed formats speed in human-readable format (e.g., "1.50 KB/s", "2.00 MB/s").
func NewCookieJar ¶
func SetDefaultClient ¶
SetDefaultClient sets a custom client as the default for package-level functions. The previous default client is closed automatically. Returns an error if the client is nil or not created with httpc.New().
func ValidateConfig ¶ added in v1.1.0
ValidateConfig validates the configuration with reasonable limits.
Types ¶
type Client ¶
type Client interface {
Get(url string, options ...RequestOption) (*Result, error)
Post(url string, options ...RequestOption) (*Result, error)
Put(url string, options ...RequestOption) (*Result, error)
Patch(url string, options ...RequestOption) (*Result, error)
Delete(url string, options ...RequestOption) (*Result, error)
Head(url string, options ...RequestOption) (*Result, error)
Options(url string, options ...RequestOption) (*Result, error)
Request(ctx context.Context, method, url string, options ...RequestOption) (*Result, error)
DownloadFile(url string, filePath string, options ...RequestOption) (*DownloadResult, error)
DownloadWithOptions(url string, downloadOpts *DownloadOptions, options ...RequestOption) (*DownloadResult, error)
Close() error
}
Client represents the HTTP client interface. All methods are safe for concurrent use by multiple goroutines.
func NewMinimal ¶ added in v1.1.0
NewMinimal creates a new client with minimal features and lightweight configuration. This preset is ideal for simple, one-off requests where you don't need retries or advanced features.
func NewPerformance ¶ added in v1.1.0
NewPerformance creates a new client optimized for high-throughput scenarios. This preset uses aggressive connection pooling, longer timeouts, and faster retry intervals for maximum performance.
type Config ¶
type Config struct {
Timeout time.Duration
MaxIdleConns int
MaxConnsPerHost int
ProxyURL string
TLSConfig *tls.Config
MinTLSVersion uint16
MaxTLSVersion uint16
InsecureSkipVerify bool
MaxResponseBodySize int64
AllowPrivateIPs bool
StrictContentLength bool
MaxRetries int
RetryDelay time.Duration
BackoffFactor float64
UserAgent string
Headers map[string]string
FollowRedirects bool
MaxRedirects int // Maximum number of redirects to follow (default: 10, 0 = no limit)
EnableHTTP2 bool
EnableCookies bool
}
Config defines the HTTP client configuration.
Thread Safety: Config must be treated as immutable after passing it to New(). Do not modify Config fields after client creation. Create a new Config for each client with different settings.
func DefaultConfig ¶
func DefaultConfig() *Config
func MinimalConfig ¶ added in v1.1.0
func MinimalConfig() *Config
MinimalConfig returns a lightweight configuration with minimal features. Use this for simple, one-off requests where you don't need retries or advanced features.
func PerformanceConfig ¶ added in v1.1.0
func PerformanceConfig() *Config
func SecureConfig ¶ added in v1.1.0
func SecureConfig() *Config
func TestingConfig ¶ added in v1.1.0
func TestingConfig() *Config
TestingConfig returns a configuration optimized for testing environments. WARNING: This config disables security features and should NEVER be used in production. Use this ONLY for local development and testing with localhost/private networks.
type DomainClient ¶ added in v1.3.0
type DomainClient struct {
// contains filtered or unexported fields
}
DomainClient provides automatic Cookie and Header management for a specific domain. All methods are safe for concurrent use by multiple goroutines.
Features: - Automatic Cookie persistence across requests - Automatic Header persistence across requests - Per-request overrides via WithCookies/WithHeaderMap - Thread-safe state management
Example:
client, _ := httpc.NewDomain("https://www.example.com")
defer client.Close()
// First request with initial cookies and headers
resp1, _ := client.Get("/",
httpc.WithCookies(initialCookies),
httpc.WithHeaderMap(map[string]string{"User-Agent": "MyBot"}),
)
// Second request automatically uses cookies from resp1 and persisted headers
// Can override with new headers
resp2, _ := client.Get("/search?q=test",
httpc.WithHeaderMap(map[string]string{"Accept": "application/json"}),
)
func NewDomain ¶ added in v1.3.0
func NewDomain(baseURL string, config ...*Config) (*DomainClient, error)
NewDomain creates a new DomainClient for the specified base URL. The base URL should include the scheme and domain (e.g., "https://www.example.com"). Returns an error if the URL is invalid or the client cannot be created.
The client automatically manages: - Cookies: Saved from responses, sent in subsequent requests - Headers: Persisted across requests unless overridden
Example:
client, err := httpc.NewDomain("https://api.example.com")
if err != nil {
log.Fatal(err)
}
defer client.Close()
func (*DomainClient) ClearCookies ¶ added in v1.3.0
func (dc *DomainClient) ClearCookies()
ClearCookies removes all persistent cookies.
func (*DomainClient) ClearHeaders ¶ added in v1.3.0
func (dc *DomainClient) ClearHeaders()
ClearHeaders removes all persistent headers.
func (*DomainClient) Close ¶ added in v1.3.0
func (dc *DomainClient) Close() error
Close closes the underlying HTTP client and releases resources.
func (*DomainClient) Delete ¶ added in v1.3.0
func (dc *DomainClient) Delete(path string, options ...RequestOption) (*Result, error)
Delete executes a DELETE request with automatic Cookie and Header management.
func (*DomainClient) DeleteCookie ¶ added in v1.3.0
func (dc *DomainClient) DeleteCookie(name string)
DeleteCookie removes a persistent cookie by name.
func (*DomainClient) DeleteHeader ¶ added in v1.3.0
func (dc *DomainClient) DeleteHeader(key string)
DeleteHeader removes a persistent header.
func (*DomainClient) Get ¶ added in v1.3.0
func (dc *DomainClient) Get(path string, options ...RequestOption) (*Result, error)
Get executes a GET request with automatic Cookie and Header management.
func (*DomainClient) GetCookie ¶ added in v1.3.0
func (dc *DomainClient) GetCookie(name string) *http.Cookie
GetCookie returns a specific persistent cookie by name. Returns nil if the cookie doesn't exist.
func (*DomainClient) GetCookies ¶ added in v1.3.0
func (dc *DomainClient) GetCookies() []*http.Cookie
GetCookies returns a copy of all persistent cookies.
func (*DomainClient) GetHeaders ¶ added in v1.3.0
func (dc *DomainClient) GetHeaders() map[string]string
GetHeaders returns a copy of all persistent headers.
func (*DomainClient) Head ¶ added in v1.3.0
func (dc *DomainClient) Head(path string, options ...RequestOption) (*Result, error)
Head executes a HEAD request with automatic Cookie and Header management.
func (*DomainClient) Options ¶ added in v1.3.0
func (dc *DomainClient) Options(path string, options ...RequestOption) (*Result, error)
Options executes an OPTIONS request with automatic Cookie and Header management.
func (*DomainClient) Patch ¶ added in v1.3.0
func (dc *DomainClient) Patch(path string, options ...RequestOption) (*Result, error)
Patch executes a PATCH request with automatic Cookie and Header management.
func (*DomainClient) Post ¶ added in v1.3.0
func (dc *DomainClient) Post(path string, options ...RequestOption) (*Result, error)
Post executes a POST request with automatic Cookie and Header management.
func (*DomainClient) Put ¶ added in v1.3.0
func (dc *DomainClient) Put(path string, options ...RequestOption) (*Result, error)
Put executes a PUT request with automatic Cookie and Header management.
func (*DomainClient) SetCookie ¶ added in v1.3.0
func (dc *DomainClient) SetCookie(cookie *http.Cookie) error
SetCookie sets a persistent cookie that will be sent with all subsequent requests. This cookie can be overridden per-request using WithCookie or WithCookies.
func (*DomainClient) SetCookies ¶ added in v1.3.0
func (dc *DomainClient) SetCookies(cookies []*http.Cookie) error
SetCookies sets multiple persistent cookies.
func (*DomainClient) SetHeader ¶ added in v1.3.0
func (dc *DomainClient) SetHeader(key, value string) error
SetHeader sets a persistent header that will be sent with all subsequent requests. This header can be overridden per-request using WithHeader or WithHeaderMap.
func (*DomainClient) SetHeaders ¶ added in v1.3.0
func (dc *DomainClient) SetHeaders(headers map[string]string) error
SetHeaders sets multiple persistent headers.
type DownloadOptions ¶
type DownloadOptions struct {
FilePath string
ProgressCallback DownloadProgressCallback
Overwrite bool
ResumeDownload bool
}
DownloadOptions configures file download behavior.
func DefaultDownloadOptions ¶
func DefaultDownloadOptions(filePath string) *DownloadOptions
DefaultDownloadOptions creates download options with default settings. Overwrite and ResumeDownload are both false by default.
type DownloadProgressCallback ¶
DownloadProgressCallback is called during file download to report progress. Parameters: downloaded bytes, total bytes, current speed in bytes/second.
type DownloadResult ¶
type DownloadResult struct {
FilePath string
BytesWritten int64
Duration time.Duration
AverageSpeed float64
StatusCode int
ContentLength int64
Resumed bool
}
DownloadResult contains information about a completed download.
func DownloadFile ¶
func DownloadFile(url string, filePath string, options ...RequestOption) (*DownloadResult, error)
DownloadFile downloads a file from the given URL to the specified file path using the default client. Returns DownloadResult with download statistics or an error if the download fails.
func DownloadWithOptions ¶
func DownloadWithOptions(url string, downloadOpts *DownloadOptions, options ...RequestOption) (*DownloadResult, error)
DownloadWithOptions downloads a file with custom download options using the default client. Returns DownloadResult with download statistics or an error if the download fails.
type Request ¶
type Request struct {
Method string
URL string
Headers map[string]string
QueryParams map[string]any
Body any
Timeout time.Duration
MaxRetries int
Context context.Context
Cookies []http.Cookie
FollowRedirects *bool // Override client's FollowRedirects setting (nil = use client default)
MaxRedirects *int // Override client's MaxRedirects setting (nil = use client default)
}
type RequestInfo ¶ added in v1.3.0
RequestInfo contains information about the HTTP request that was sent.
type RequestMeta ¶ added in v1.3.0
type RequestMeta struct {
Duration time.Duration
Attempts int
RedirectChain []string
RedirectCount int
}
RequestMeta contains metadata about the request execution.
type RequestOption ¶
func WithAccept ¶
func WithAccept(accept string) RequestOption
WithAccept sets the Accept header for the request.
func WithBasicAuth ¶
func WithBasicAuth(username, password string) RequestOption
WithBasicAuth adds HTTP Basic Authentication to the request. The credentials are base64-encoded and added to the Authorization header. Returns an error if username is empty or credentials contain invalid characters.
func WithBearerToken ¶
func WithBearerToken(token string) RequestOption
WithBearerToken adds a Bearer token to the Authorization header. Returns an error if token is empty, too long, or contains invalid characters.
func WithBinary ¶
func WithBinary(data []byte, contentType ...string) RequestOption
func WithBody ¶
func WithBody(body any) RequestOption
func WithContentType ¶
func WithContentType(contentType string) RequestOption
WithContentType sets the Content-Type header for the request.
func WithContext ¶
func WithContext(ctx context.Context) RequestOption
func WithCookie ¶
func WithCookie(cookie http.Cookie) RequestOption
func WithCookieString ¶ added in v1.3.0
func WithCookieString(cookieString string) RequestOption
WithCookieString parses a cookie string and adds all cookies to the request. The cookie string should be in the format: "name1=value1; name2=value2; name3=value3" This is commonly used when copying cookies from browser developer tools or server responses. Each cookie is created with secure defaults: HttpOnly=true, SameSite=Lax. Returns an error if the cookie string is malformed or contains invalid cookie names/values.
Example:
WithCookieString("BPSID=4418ECBB1281B550; PSTM=1733760779; BDS=kUwNTVFcEUBUItoc")
func WithCookieValue ¶
func WithCookieValue(name, value string) RequestOption
WithCookieValue adds a cookie with the given name and value to the request. The cookie is created with secure defaults: HttpOnly=true, SameSite=Lax. The domain should be set explicitly using WithCookie if needed. For HTTPS requests, consider using WithCookie with Secure=true. Returns an error if name is empty or contains invalid characters.
func WithCookies ¶
func WithCookies(cookies []http.Cookie) RequestOption
func WithFile ¶
func WithFile(fieldName, filename string, content []byte) RequestOption
WithFile adds a file upload to the request. Returns an error if fieldName or filename is empty or contains invalid characters.
func WithFollowRedirects ¶ added in v1.3.0
func WithFollowRedirects(follow bool) RequestOption
WithFollowRedirects enables or disables automatic redirect following for this request. This overrides the client's FollowRedirects configuration. When disabled, the client returns the redirect response (3xx) without following it.
func WithForm ¶
func WithForm(data map[string]string) RequestOption
func WithFormData ¶
func WithFormData(data *FormData) RequestOption
func WithHeader ¶
func WithHeader(key, value string) RequestOption
WithHeader adds a custom header to the request. Returns an error if the header key or value is invalid.
func WithHeaderMap ¶
func WithHeaderMap(headers map[string]string) RequestOption
WithHeaderMap adds multiple headers to the request. Returns an error if any header key or value is invalid.
func WithJSON ¶
func WithJSON(data any) RequestOption
WithJSON sets the request body to JSON-encoded data and sets Content-Type to application/json.
func WithJSONAccept ¶
func WithJSONAccept() RequestOption
WithJSONAccept sets the Accept header to application/json.
func WithMaxRedirects ¶ added in v1.3.0
func WithMaxRedirects(maxRedirects int) RequestOption
WithMaxRedirects sets the maximum number of redirects to follow for this request. This overrides the client's MaxRedirects configuration. Set to 0 to allow unlimited redirects (not recommended). Returns an error if maxRedirects is negative or exceeds 50.
func WithMaxRetries ¶
func WithMaxRetries(maxRetries int) RequestOption
WithMaxRetries sets the maximum number of retry attempts. Returns ErrInvalidRetry if maxRetries is not between 0 and 10.
func WithQuery ¶
func WithQuery(key string, value any) RequestOption
WithQuery adds a single query parameter to the request URL. Returns an error if key is empty, too long, or contains invalid characters.
func WithQueryMap ¶
func WithQueryMap(params map[string]any) RequestOption
WithQueryMap adds multiple query parameters to the request URL. Returns an error if any key is empty, too long, or contains invalid characters.
func WithText ¶
func WithText(content string) RequestOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) RequestOption
WithTimeout sets the request timeout. Returns ErrInvalidTimeout if timeout is negative or exceeds 30 minutes.
func WithUserAgent ¶
func WithUserAgent(userAgent string) RequestOption
WithUserAgent sets the User-Agent header for the request.
func WithXML ¶
func WithXML(data any) RequestOption
WithXML sets the request body to XML-encoded data and sets Content-Type to application/xml.
func WithXMLAccept ¶
func WithXMLAccept() RequestOption
WithXMLAccept sets the Accept header to application/xml.
type Response ¶
type Response struct {
StatusCode int
Status string
Headers http.Header
Body string
RawBody []byte
ContentLength int64
Duration time.Duration
Attempts int
Cookies []*http.Cookie
RedirectChain []string
RedirectCount int
RequestHeaders http.Header
}
Response represents an HTTP response. Deprecated: Use Result instead for new code. This type is maintained for backward compatibility only.
func (*Response) GetRequestCookie ¶ added in v1.3.0
GetRequestCookie returns a specific cookie from the request by name.
func (*Response) GetRequestCookies ¶ added in v1.3.0
GetRequestCookies extracts cookies from the request Cookie header.
func (*Response) HasRequestCookie ¶ added in v1.3.0
HasRequestCookie checks if a specific cookie was sent in the request.
func (*Response) IsClientError ¶
IsClientError returns true if the response status code indicates a client error (4xx).
func (*Response) IsRedirect ¶
IsRedirect returns true if the response status code indicates a redirect (3xx).
func (*Response) IsServerError ¶
IsServerError returns true if the response status code indicates a server error (5xx).
func (*Response) IsSuccess ¶
IsSuccess returns true if the response status code indicates success (2xx).
type ResponseInfo ¶ added in v1.3.0
type ResponseInfo struct {
StatusCode int
Status string
Headers http.Header
Body string
RawBody []byte
ContentLength int64
Cookies []*http.Cookie
}
ResponseInfo contains the HTTP response data received from the server.
type Result ¶ added in v1.3.0
type Result struct {
Request *RequestInfo
Response *ResponseInfo
Meta *RequestMeta
}
Result represents the complete outcome of an HTTP request. It provides clear separation between request information, response data, and metadata.
Thread Safety: Result objects are immutable after creation and safe to read from multiple goroutines concurrently. Do not modify Result fields directly.
func Delete ¶
func Delete(url string, options ...RequestOption) (*Result, error)
Delete executes a DELETE request using the default client and returns a Result.
func Get ¶
func Get(url string, options ...RequestOption) (*Result, error)
Get executes a GET request using the default client and returns a Result.
func Head ¶
func Head(url string, options ...RequestOption) (*Result, error)
Head executes a HEAD request using the default client and returns a Result.
func Options ¶
func Options(url string, options ...RequestOption) (*Result, error)
Options executes an OPTIONS request using the default client and returns a Result.
func Patch ¶
func Patch(url string, options ...RequestOption) (*Result, error)
Patch executes a PATCH request using the default client and returns a Result.
func Post ¶
func Post(url string, options ...RequestOption) (*Result, error)
Post executes a POST request using the default client and returns a Result.
func Put ¶
func Put(url string, options ...RequestOption) (*Result, error)
Put executes a PUT request using the default client and returns a Result.
func (*Result) Body ¶ added in v1.3.0
Body returns the response body as a string. This is a convenience method equivalent to accessing Result.Response.Body.
func (*Result) GetCookie ¶ added in v1.3.0
GetCookie returns a specific cookie from the response by name. This returns cookies from the server's Set-Cookie header (response cookies).
func (*Result) GetRequestCookie ¶ added in v1.3.0
GetRequestCookie returns a specific cookie from the request by name.
func (*Result) HasCookie ¶ added in v1.3.0
HasCookie checks if a specific cookie exists in the response.
func (*Result) HasRequestCookie ¶ added in v1.3.0
HasRequestCookie checks if a specific cookie was sent in the request.
func (*Result) Html ¶ added in v1.3.0
Html returns the response body as HTML content. This is an alias for Body() method.
func (*Result) IsClientError ¶ added in v1.3.0
IsClientError returns true if the response status code indicates a client error (4xx).
func (*Result) IsRedirect ¶ added in v1.3.0
IsRedirect returns true if the response status code indicates a redirect (3xx).
func (*Result) IsServerError ¶ added in v1.3.0
IsServerError returns true if the response status code indicates a server error (5xx).
func (*Result) IsSuccess ¶ added in v1.3.0
IsSuccess returns true if the response status code indicates success (2xx).
func (*Result) JSON ¶ added in v1.3.0
JSON unmarshals the response body into the provided interface. Returns ErrResponseBodyEmpty if the body is nil or empty. Returns ErrResponseBodyTooLarge if the body exceeds 50MB.
func (*Result) RawBody ¶ added in v1.3.0
RawBody returns the response body as raw bytes. This is a convenience method equivalent to accessing Result.Response.RawBody.
func (*Result) RequestCookies ¶ added in v1.3.0
RequestCookies returns the cookies that were sent with the request. This is a convenience method equivalent to accessing Result.Request.Cookies.
func (*Result) ResponseCookies ¶ added in v1.3.0
ResponseCookies returns the cookies received in the response. This is a convenience method equivalent to accessing Result.Response.Cookies.
func (*Result) SaveToFile ¶ added in v1.3.0
SaveToFile saves the response body to a file. Returns ErrResponseBodyEmpty if the body is nil or empty.
func (*Result) StatusCode ¶ added in v1.3.0
StatusCode returns the HTTP status code. This is a convenience method equivalent to accessing Result.Response.StatusCode.