http

package
v0.0.0-...-1ce522b Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package http implements a set of utilities related to the HTTP protocol.

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 NewClient

func NewClient(url string) *Client

NewClient returns a new HTTP client.

func NewClientWithAuthorization

func NewClientWithAuthorization(url, authorization string) *Client

NewClientWithAuthorization returns a new client with a custom authorization header.

func NewClientWithCacheHeaders

func NewClientWithCacheHeaders(url, etagHeader, lastModifiedHeader string) *Client

NewClientWithCacheHeaders returns a new HTTP client that send cache headers.

func NewClientWithCredentials

func NewClientWithCredentials(url, username, password string) *Client

NewClientWithCredentials returns a new HTTP client that requires authentication.

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.

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) 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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