httplib

package
v1.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultSetting

func SetDefaultSetting(setting Settings)

SetDefaultSetting overwrites default settings

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

Types

type Request

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

Request provides more useful methods for requesting one url than http.Request.

func Delete

func Delete(url string) *Request

Delete returns *Request DELETE method.

func Get

func Get(url string) *Request

Get returns *Request with GET method.

func Head(url string) *Request

Head returns *Request with HEAD method.

func NewRequest added in v1.2.0

func NewRequest(url, method string) *Request

NewRequest returns *Request with specific method

func Post

func Post(url string) *Request

Post returns *Request with POST method.

func Put

func Put(url string) *Request

Put returns *Request with PUT method.

func (*Request) Body

func (r *Request) Body(data interface{}) *Request

Body adds request raw body. it supports string and []byte.

func (*Request) Bytes

func (r *Request) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*Request) Debug

func (r *Request) Debug(isdebug bool) *Request

Debug sets show debug or not when executing request.

func (*Request) Header

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

Header add header item string in request.

func (*Request) Headers

func (r *Request) Headers() http.Header

Headers returns headers in request.

func (*Request) Param

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

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) PostFile

func (r *Request) PostFile(formname, filename string) *Request

PostFile uploads file via http

func (*Request) Response

func (r *Request) Response() (*http.Response, error)

Response executes request client gets response manually.

func (*Request) SetBasicAuth

func (r *Request) SetBasicAuth(username, password string) *Request

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*Request) SetCookie

func (r *Request) SetCookie(cookie *http.Cookie) *Request

SetCookie add cookie into request.

func (*Request) SetEnableCookie

func (r *Request) SetEnableCookie(enable bool) *Request

SetEnableCookie sets enable/disable cookiejar

func (*Request) SetProtocolVersion

func (r *Request) SetProtocolVersion(vers string) *Request

SetProtocolVersion sets the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*Request) SetProxy

func (r *Request) SetProxy(proxy func(*http.Request) (*url.URL, error)) *Request

SetProxy sets http proxy example:

func(req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
	return u, nil
}

func (*Request) SetTLSClientConfig

func (r *Request) SetTLSClientConfig(config *tls.Config) *Request

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*Request) SetTimeout

func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Request

SetTimeout sets connect time out and read-write time out for BeegoRequest.

func (*Request) SetTransport

func (r *Request) SetTransport(transport http.RoundTripper) *Request

SetTransport sets transport to

func (*Request) SetUserAgent

func (r *Request) SetUserAgent(useragent string) *Request

SetUserAgent sets User-Agent header field

func (*Request) Setting

func (r *Request) Setting(setting Settings) *Request

Setting changes request settings

func (*Request) String

func (r *Request) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*Request) ToFile

func (r *Request) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*Request) ToJSON added in v1.0.0

func (r *Request) ToJSON(v interface{}) error

ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*Request) ToXML added in v1.0.0

func (r *Request) ToXML(v interface{}) error

ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type Settings

type Settings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TLSClientConfig  *tls.Config
	Proxy            func(*http.Request) (*url.URL, error)
	Transport        http.RoundTripper
	EnableCookie     bool
}

Settings is the default settings for http client

Jump to

Keyboard shortcuts

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