client

package
v0.0.0-...-5365f31 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2018 License: Apache-2.0 Imports: 18 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 {
	Insecure bool
	// contains filtered or unexported fields
}

Client is a HTTP Client :)

func New

func New(url string) *Client

New returns a new HTTP client.

func (*Client) Get

func (c *Client) Get() (*Response, error)

Get execute a GET HTTP request.

func (*Client) PostForm

func (c *Client) PostForm(values url.Values) (*Response, error)

PostForm execute a POST HTTP request with form values.

func (*Client) PostJSON

func (c *Client) PostJSON(data interface{}) (*Response, error)

PostJSON execute a POST HTTP request with JSON payload.

func (*Client) WithAuthorization

func (c *Client) WithAuthorization(authorization string) *Client

WithAuthorization defines authorization header value.

func (*Client) WithCacheHeaders

func (c *Client) WithCacheHeaders(etagHeader, lastModifiedHeader string) *Client

WithCacheHeaders defines caching headers.

func (*Client) WithCredentials

func (c *Client) WithCredentials(username, password string) *Client

WithCredentials defines the username/password for HTTP Basic authentication.

type Response

type Response struct {
	Body          io.Reader
	StatusCode    int
	EffectiveURL  string
	LastModified  string
	ETag          string
	ContentType   string
	ContentLength int64
}

Response wraps a server response.

func (*Response) HasServerFailure

func (r *Response) HasServerFailure() bool

HasServerFailure returns true if the status code represents a failure.

func (*Response) IsModified

func (r *Response) IsModified(etag, lastModified string) bool

IsModified returns true if the resource has been modified.

func (*Response) IsNotAuthorized

func (r *Response) IsNotAuthorized() bool

IsNotAuthorized returns true if the resource require authentication.

func (*Response) IsNotFound

func (r *Response) IsNotFound() bool

IsNotFound returns true if the resource doesn't exists anymore.

func (*Response) NormalizeBodyEncoding

func (r *Response) NormalizeBodyEncoding() (io.Reader, error)

NormalizeBodyEncoding make sure the body is encoded in UTF-8.

If a charset other than UTF-8 is detected, we convert the document to UTF-8. This is used by the scraper and feed readers.

Do not forget edge cases: - Some non-utf8 feeds specify encoding only in Content-Type, not in XML document.

Jump to

Keyboard shortcuts

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