Documentation ¶
Index ¶
- type AsyncURL
- type Client
- func (c *Client) ClientMiddleware(m clientMiddleware) *Client
- func (c *Client) Delete(rawURL string, data ...any) *Request
- func (c *Client) FileUpload(rawURL, fieldName, filePath string, data ...any) *Request
- func (c *Client) Get(rawURL string, data ...any) *Request
- func (c *Client) GetClient() *http.Client
- func (c *Client) GetDialer() *net.Dialer
- func (c *Client) GetTLSConfig() *tls.Config
- func (c *Client) GetTransport() *http.Transport
- func (c *Client) Head(rawURL string) *Request
- func (c *Client) Multipart(rawURL string, multipartValues map[string]string) *Request
- func (c *Client) Patch(rawURL string, data any) *Request
- func (c *Client) Post(rawURL string, data any) *Request
- func (c *Client) Put(rawURL string, data any) *Request
- func (c *Client) RequestMiddleware(m requestMiddleware) *Client
- func (c *Client) ResponseMiddleware(m responseMiddleware) *Client
- func (c *Client) SetOptions(opt *Options) *Client
- type Options
- func (opt *Options) BasicAuth(authentication any) *Options
- func (opt *Options) BearerAuth(authentication string) *Options
- func (opt *Options) CacheBody(enable ...bool) *Options
- func (opt *Options) ContentType(contentType string) *Options
- func (opt *Options) DNS(dns string) *Options
- func (opt *Options) DNSCache(ttl time.Duration, maxUsage int64) *Options
- func (opt *Options) DNSOverTLS() *dnsOverTLS
- func (opt *Options) DisableKeepAlive() *Options
- func (opt *Options) FollowOnlyHostRedirects() *Options
- func (opt *Options) ForwardHeadersOnRedirect() *Options
- func (opt *Options) GetRemoteAddress() *Options
- func (opt *Options) HTTP2(enable ...bool) *Options
- func (opt *Options) History() *Options
- func (opt *Options) InterfaceAddr(address string) *Options
- func (opt *Options) MaxRedirects(maxRedirects int) *Options
- func (opt *Options) Proxy(proxy any) *Options
- func (opt *Options) RedirectPolicy(f func(*http.Request, []*http.Request) error) *Options
- func (opt *Options) Retry(retryMax int, retryWait ...time.Duration) *Options
- func (opt *Options) Session() *Options
- func (opt Options) String() string
- func (opt *Options) Timeout(timeout time.Duration) *Options
- func (opt *Options) UnixDomainSocket(socketPath string) *Options
- func (opt *Options) UserAgent(userAgent any) *Options
- type Request
- func (req *Request) AddCookies(cookies ...http.Cookie) *Request
- func (req *Request) AddHeaders(headers map[string]string) *Request
- func (req *Request) Do() (*Response, error)
- func (req *Request) GetRequest() *http.Request
- func (req *Request) SetHeaders(headers map[string]string) *Request
- func (req *Request) WithContext(ctx context.Context) *Request
- type Requests
- type Response
- func (resp Response) Debug() *debug
- func (resp Response) GetCookies(rawURL string) []*http.Cookie
- func (resp Response) GetResponse() *http.Response
- func (resp Response) Referer() string
- func (resp Response) RemoteAddress() net.Addr
- func (resp *Response) SetCookies(rawURL string, cookies []*http.Cookie) error
- func (resp Response) TLSGrabber() *tlsData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncURL ¶
type AsyncURL struct {
// contains filtered or unexported fields
}
AsyncURL struct represents an asynchronous URL with additional information such as data, context, setHeaders, addHeaders, and url.
func NewAsyncURL ¶
NewAsyncURL creates a new AsyncURL object with the provided URL string and returns a pointer to it.
func (*AsyncURL) AddCookies ¶ added in v1.0.14
AddCookies adds cookies to the AsyncURL object and returns a pointer to the updated object.
func (*AsyncURL) AddHeaders ¶
AddHeaders adds headers to the AsyncURL object and returns a pointer to the updated object.
func (*AsyncURL) Context ¶
Context sets the context of the AsyncURL object and returns a pointer to the updated object.
type Client ¶
type Client struct { Async *async // contains filtered or unexported fields }
Client struct provides a customizable HTTP client with configurable options for making requests, handling connections, and managing TLS settings.
func (*Client) ClientMiddleware ¶ added in v1.0.30
ClientMiddleware add a client middleware.
func (*Client) FileUpload ¶
FileUpload creates a new multipart file upload request.
func (*Client) GetTLSConfig ¶ added in v1.0.30
GetTLSClientConfig returns the tls.Config used by the Client.
func (*Client) GetTransport ¶
GetTransport returns the http.transport used by the Client.
func (*Client) RequestMiddleware ¶ added in v1.0.30
RequestMiddleware add a request middleware which hooks before request sent.
func (*Client) ResponseMiddleware ¶ added in v1.0.30
ResponseMiddleware add a response middleware which hooks after response received.
func (*Client) SetOptions ¶
SetOptions sets the provided options for the client and returns the updated client. It configures various settings like HTTP2, sessions, keep-alive, dial TLS, resolver, interface address, timeout, and redirect policy.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options a struct that holds options for configuring the HTTP client.
func NewOptions ¶
func NewOptions() *Options
NewOptions creates a new Options instance with default values.
func (*Options) BearerAuth ¶
BearerAuth sets the bearer token for the client.
func (*Options) CacheBody ¶
CacheBody configures whether the client should cache the body of the response.
func (*Options) ContentType ¶
ContentType sets the content type for the client.
func (*Options) DNSCache ¶ added in v1.0.21
DNSCache configures the DNS cache settings of the HTTP client.
DNS caching can improve the performance of HTTP clients by caching the DNS lookup results for the specified Time-To-Live (TTL) duration and limiting the usage of the cached DNS result.
Parameters:
- ttl: the TTL duration for the DNS cache. After this duration, the DNS cache for a host will be invalidated.
- maxUsage: the maximum number of times a cached DNS lookup result can be used. After this number is reached, the DNS cache for a host will be invalidated.
Returns the same Options object, allowing for chaining of configuration calls.
Example:
opt := hhttp.NewOptions().DNSCache(time.Second*30, 10) cli := hhttp.NewClient().SetOptions(opt)
The client will now use a DNS cache with a 30-second TTL and a maximum usage count of 10.
func (*Options) DNSOverTLS ¶
func (opt *Options) DNSOverTLS() *dnsOverTLS
DNSOverTLS configures the client to use DNS over TLS.
func (*Options) DisableKeepAlive ¶ added in v1.0.33
DisableKeepAlive disable keep-alive connections.
func (*Options) FollowOnlyHostRedirects ¶
FollowOnlyHostRedirects configures whether the client should only follow redirects within the same host.
func (*Options) ForwardHeadersOnRedirect ¶ added in v1.0.34
ForwardHeadersOnRedirect adds a middleware to the Options object that ensures HTTP headers are forwarded during a redirect.
func (*Options) GetRemoteAddress ¶
GetRemoteAddress configures whether the client should get the remote address.
func (*Options) History ¶
History configures whether the client should keep a history of requests (for debugging purposes only). WARNING: use only for debugging, not in async mode, no concurrency safe!!!
func (*Options) InterfaceAddr ¶
InterfaceAddr sets the network interface address for the client.
func (*Options) MaxRedirects ¶
MaxRedirects sets the maximum number of redirects the client should follow.
func (*Options) RedirectPolicy ¶
RedirectPolicy sets a custom redirect policy for the client.
func (*Options) UnixDomainSocket ¶ added in v1.0.2
UnixDomainSocket sets the path for a Unix domain socket in the Options. This allows the HTTP client to connect to the server using a Unix domain socket instead of a traditional TCP/IP connection.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request a struct that holds information about an HTTP request.
func (*Request) AddCookies ¶
AddCookies adds cookies to the request.
func (*Request) AddHeaders ¶
AddHeaders adds headers to the request, appending to any existing headers with the same name.
func (*Request) Do ¶
Do performs the HTTP request and returns a Response object or an error if the request failed.
func (*Request) GetRequest ¶ added in v1.0.30
func (*Request) SetHeaders ¶
SetHeaders sets headers for the request, replacing existing ones with the same name.
type Requests ¶
type Requests struct {
// contains filtered or unexported fields
}
Requests a struct that manages concurrent HTTP requests.
func (*Requests) Do ¶
Do performs all queued requests concurrently, returning channels with results and errors.
func (*Requests) RateLimiter ¶
RateLimiter sets a rate limiter for the concurrent requests, limiting the number of requests per second.
type Response ¶
type Response struct { *Client URL *url.URL Body *body Headers headers Status string UserAgent string Proto string History history Cookies cookies Time time.Duration ContentLength int64 StatusCode int Attempts int // contains filtered or unexported fields }
func (Response) GetCookies ¶
GetCookies returns the cookies from the response for the given URL.
func (Response) GetResponse ¶ added in v1.0.36
func (Response) RemoteAddress ¶ added in v1.0.10
RemoteAddress returns the remote address of the response.
func (*Response) SetCookies ¶
SetCookies sets cookies for the given URL in the response.
func (Response) TLSGrabber ¶
func (resp Response) TLSGrabber() *tlsData
TLSGrabber returns a tlsData struct containing information about the TLS connection if it exists.