hclient

package
v0.0.0-...-6c32bbf Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoCookieJarErr = errors.New("no cookie jar in client")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	LatestResponse *Response
	// contains filtered or unexported fields
}

func NewClient

func NewClient(parameters ...string) (*Client, error)

NewClient creates a new http client Takes in the optional arguments: proxy, servername

func (*Client) AddCookie

func (c *Client) AddCookie(u *url.URL, cookie *http.Cookie) error

AddCookie adds a new cookie to the request client cookie jar

func (*Client) Do

func (c *Client) Do(r *http.Request) (*Response, error)

Do will send the specified request

func (*Client) NewRequest

func (c *Client) NewRequest() *Request

NewRequest creates a new request under a specified http client

func (*Client) RemoveCookie

func (c *Client) RemoveCookie(u *url.URL, cookie string) error

RemoveCookie removes the specified cookie from the request client cookie jar

type Request

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

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string) *Request

AddHeader adds a specified header to the request If the header already exists, the value will be appended by the new specified value If the header does not exist, the header will be set to the specified value

func (*Request) Do

func (r *Request) Do() (*Response, error)

Do will send the request with all specified request values

func (*Request) SetFormBody

func (r *Request) SetFormBody(body url.Values) *Request

SetFormBody sets the body to a form value

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

SetHeader sets a specified header to the request This overrides any previously set values of the specified header

func (*Request) SetHost

func (r *Request) SetHost(value string) *Request

SetHost sets the host of the request

func (*Request) SetJSONBody

func (r *Request) SetJSONBody(body interface{}) *Request

SetJSONBody sets the body to a json value

func (*Request) SetMethod

func (r *Request) SetMethod(method string) *Request

SetMethod sets the method of the request

func (*Request) SetURL

func (r *Request) SetURL(url string) *Request

SetURL sets the url of the request

type Response

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

func (*Response) Body

func (r *Response) Body() []byte

Body returns the response body

func (*Response) BodyAsJSON

func (r *Response) BodyAsJSON(data interface{}) error

BodyAsJSON unmarshalls the current response body to the specified data structure

func (*Response) BodyAsString

func (r *Response) BodyAsString() string

BodyAsString returns the response body as a string

func (*Response) Header

func (r *Response) Header() http.Header

Header returns the response headers

func (*Response) Status

func (r *Response) Status() string

Status returns the response status

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns the response status code

Jump to

Keyboard shortcuts

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