easyclient

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Holds a *http.Client and the specified headers as those can't be saved on the client session directly.

func NewClient

func NewClient(options ClientOptions) (*Client, error)

Returns a new Client type.

func (*Client) ClearCookies

func (c *Client) ClearCookies() error

Clears all cookies on the client.

func (*Client) ClearHeaders

func (c *Client) ClearHeaders()

Clears all headers on the client.

func (*Client) ClearProxy

func (c *Client) ClearProxy()

Clears the proxy from the client. Warning: This will overwrite the existing transport.

func (*Client) Do

func (c *Client) Do(options RequestOptions) (*http.Response, []byte, error)

Executes the request.

func (*Client) GetCookies

func (c *Client) GetCookies(baseURL string) ([]*http.Cookie, error)

Returns all cookies set on the client.

func (*Client) SetCookies

func (c *Client) SetCookies(URL string, cookieMap map[string]string) error

Sets cookies on the client which will be reused on every request.

func (*Client) SetFollowRedirects

func (c *Client) SetFollowRedirects(shouldRedirect bool)

Specify if the client should follow redirects.

func (*Client) SetHeaders

func (c *Client) SetHeaders(headers map[string]string)

Sets headers on the client which will be reused on every request.

func (*Client) SetProxy

func (c *Client) SetProxy(proxy string) error

Sets a proxy to the client.

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

Sets the timeout duration for the client.

func (*Client) SetTransport

func (c *Client) SetTransport(transport http.RoundTripper)

Sets the transport for the client.

type ClientOptions

type ClientOptions struct {
	Cookies         ClientOptionsCookies // Custom cookies set on the client.
	FollowRedirects bool                 // If true, the client will follow redirects.
	Headers         map[string]string    // Custom headers set to the client.
	Proxy           string               // Custom proxy set to the client.
	Timeout         time.Duration        // Set custom request timeout. If nil, 30 * time.Second is used.
	Transport       http.RoundTripper    // Set custom transport type. If nil, http.DefaultTransport is used.
}

Specifies default values when creating a new Client.

type ClientOptionsCookies

type ClientOptionsCookies struct {
	BaseURL string            // The URL of the page to set the cookies on.
	Cookies map[string]string // A map of cookies to set.
}

type RequestOptions

type RequestOptions struct {
	Body             io.Reader         // Body data to include in the request.
	Cookies          map[string]string // A map of cookies to set for the request.
	Headers          map[string]string // A map of headers to set for the request.
	Method           string            // The HTTP-Method.
	ReadResponseBody bool              // Whether the response.Body should be parsed or not.
	Proxy            string            // Custom proxy for the request.
	URL              string            // URL to perform the request on.
}

RequestOptions specifies details when making a new request.

Jump to

Keyboard shortcuts

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