client

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package client provides an HTTP client with support for various authentication schemes, cookies, proxies, TLS certificates, and response timing.

Package client provides HTTP client implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResponseCookies added in v0.2.5

func GetResponseCookies(resp *http.Response) []*http.Cookie

GetResponseCookies extracts cookies from an HTTP response

Types

type Certificate

type Certificate struct {
	Cert       string
	Key        string
	PFX        string
	Passphrase string
}

Certificate holds TLS certificate configuration

type ClientConfig

type ClientConfig struct {
	Timeout         time.Duration
	FollowRedirects bool
	InsecureSSL     bool
	Proxy           string
	ExcludeProxy    []string
	RememberCookies bool
	DefaultHeaders  map[string]string
	Certificates    map[string]Certificate
}

ClientConfig holds client configuration

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns a default client configuration

type HTTPDoer added in v0.2.10

type HTTPDoer interface {
	Send(request *models.HttpRequest) (*models.HttpResponse, error)
	SendWithContext(ctx context.Context, request *models.HttpRequest) (*models.HttpResponse, error)
	GetCookies(urlStr string) []*http.Cookie
	SetCookies(urlStr string, cookies []*http.Cookie)
	ClearCookies()
}

HTTPDoer defines the interface for sending HTTP requests. This abstraction enables dependency injection and easier testing.

type HttpClient

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

HttpClient is an HTTP client with auth support

func NewHttpClient

func NewHttpClient(config *ClientConfig) (*HttpClient, error)

NewHttpClient creates a new HTTP client

func (*HttpClient) ClearCookies

func (c *HttpClient) ClearCookies()

ClearCookies clears all stored cookies

func (*HttpClient) GetCookies added in v0.2.5

func (c *HttpClient) GetCookies(urlStr string) []*http.Cookie

GetCookies returns all cookies for a given URL

func (*HttpClient) Send

func (c *HttpClient) Send(request *models.HttpRequest) (*models.HttpResponse, error)

Send sends an HTTP request and returns the response

func (*HttpClient) SendWithContext

func (c *HttpClient) SendWithContext(ctx context.Context, request *models.HttpRequest) (*models.HttpResponse, error)

SendWithContext sends an HTTP request with context

func (*HttpClient) SetCookies added in v0.2.5

func (c *HttpClient) SetCookies(urlStr string, cookies []*http.Cookie)

SetCookies sets cookies for a given URL

type MockHTTPClient added in v0.2.10

type MockHTTPClient struct {

	// Response is the response to return from Send/SendWithContext.
	Response *models.HttpResponse

	// Error is the error to return from Send/SendWithContext.
	Error error

	// Requests records all requests made to this mock.
	Requests []*models.HttpRequest

	// ResponseFunc allows dynamic response generation based on the request.
	// If set, it takes precedence over Response/Error fields.
	ResponseFunc func(req *models.HttpRequest) (*models.HttpResponse, error)

	// Cookies stores cookies by URL for GetCookies/SetCookies.
	Cookies map[string][]*http.Cookie
	// contains filtered or unexported fields
}

MockHTTPClient is a mock implementation of HTTPDoer for testing. It allows setting up expected responses and recording request history.

func NewMockHTTPClient added in v0.2.10

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new MockHTTPClient.

func (*MockHTTPClient) ClearCookies added in v0.2.10

func (m *MockHTTPClient) ClearCookies()

ClearCookies removes all stored cookies.

func (*MockHTTPClient) GetCookies added in v0.2.10

func (m *MockHTTPClient) GetCookies(urlStr string) []*http.Cookie

GetCookies returns cookies for the given URL.

func (*MockHTTPClient) LastRequest added in v0.2.10

func (m *MockHTTPClient) LastRequest() *models.HttpRequest

LastRequest returns the most recent request, or nil if none recorded.

func (*MockHTTPClient) RequestCount added in v0.2.10

func (m *MockHTTPClient) RequestCount() int

RequestCount returns the number of requests recorded.

func (*MockHTTPClient) Reset added in v0.2.10

func (m *MockHTTPClient) Reset()

Reset clears all recorded requests and stored cookies.

func (*MockHTTPClient) Send added in v0.2.10

func (m *MockHTTPClient) Send(request *models.HttpRequest) (*models.HttpResponse, error)

Send sends an HTTP request and returns the mock response.

func (*MockHTTPClient) SendWithContext added in v0.2.10

func (m *MockHTTPClient) SendWithContext(ctx context.Context, request *models.HttpRequest) (*models.HttpResponse, error)

SendWithContext sends an HTTP request with context and returns the mock response.

func (*MockHTTPClient) SetCookies added in v0.2.10

func (m *MockHTTPClient) SetCookies(urlStr string, cookies []*http.Cookie)

SetCookies sets cookies for the given URL.

func (*MockHTTPClient) WithError added in v0.2.10

func (m *MockHTTPClient) WithError(err error) *MockHTTPClient

WithError sets the error to return and returns the mock for chaining.

func (*MockHTTPClient) WithResponse added in v0.2.10

func (m *MockHTTPClient) WithResponse(resp *models.HttpResponse) *MockHTTPClient

WithResponse sets the response to return and returns the mock for chaining.

func (*MockHTTPClient) WithResponseFunc added in v0.2.10

func (m *MockHTTPClient) WithResponseFunc(fn func(req *models.HttpRequest) (*models.HttpResponse, error)) *MockHTTPClient

WithResponseFunc sets a dynamic response function and returns the mock for chaining.

Jump to

Keyboard shortcuts

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