http

package
v0.0.0-...-5df1a6f Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultSetting

func SetDefaultSetting(setting HTTPSettings)

SetDefaultSetting Overwrite 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 web.Transport Dial field.

Types

type Context

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

一个请求上下文

func Get

func Get(url string) *Context

func NewRequest

func NewRequest(rawurl, method string) *Context

func Post

func Post(url string) *Context

func (*Context) Body

func (b *Context) Body(data interface{}) *Context

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

func (*Context) Bytes

func (b *Context) Bytes() ([]byte, error)

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

func (*Context) Debug

func (b *Context) Debug(isdebug bool) *Context

Debug sets show debug or not when executing request.

func (*Context) DoRequest

func (b *Context) DoRequest() (resp *http.Response, err error)

DoRequest will do the client.Do

func (*Context) DumpBody

func (b *Context) DumpBody(isdump bool) *Context

DumpBody setting whether need to Dump the Body.

func (*Context) DumpRequest

func (b *Context) DumpRequest() []byte

DumpRequest return the DumpRequest

func (*Context) GetRequest

func (b *Context) GetRequest() *http.Request

获取request对象

func (*Context) Header

func (b *Context) Header(key, value string) *Context

Header add header item string in request.

func (*Context) JSONBody

func (b *Context) JSONBody(obj interface{}) (*Context, error)

JSONBody adds request raw body encoding by JSON.

func (*Context) Param

func (b *Context) Param(key, value string) *Context

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

func (*Context) PostFile

func (b *Context) PostFile(formname, filename string) *Context

PostFile add a post file to the request

func (*Context) Response

func (b *Context) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*Context) Retries

func (b *Context) Retries(times int) *Context

Retries sets Retries times. default is 0 means no retried. -1 means retried forever. others means retried times.

func (*Context) SetBasicAuth

func (b *Context) SetBasicAuth(username, password string) *Context

request的代理方法

func (*Context) SetCheckRedirect

func (b *Context) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *Context

SetCheckRedirect specifies the policy for handling redirects.

If CheckRedirect is nil, the Client uses its default policy, which is to stop after 10 consecutive requests.

func (*Context) SetCookie

func (b *Context) SetCookie(cookie *http.Cookie) *Context

SetCookie add cookie into request.

func (*Context) SetEnableCookie

func (b *Context) SetEnableCookie(enable bool) *Context

request的代理方法

func (*Context) SetHost

func (b *Context) SetHost(host string) *Context

SetHost set the request host

func (*Context) SetProtocolVersion

func (b *Context) SetProtocolVersion(vers string) *Context

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

func (*Context) SetProxy

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

SetProxy set the web api example:

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

func (*Context) SetTLSClientConfig

func (b *Context) SetTLSClientConfig(config *tls.Config) *Context

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*Context) SetTimeout

func (b *Context) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Context

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

func (*Context) SetTransport

func (b *Context) SetTransport(transport http.RoundTripper) *Context

SetTransport set the setting transport

func (*Context) SetUserAgent

func (b *Context) SetUserAgent(useragent string) *Context

SetUserAgent sets User-Agent header field

func (*Context) Setting

func (b *Context) Setting(setting HTTPSettings) *Context

设置请求

func (*Context) String

func (b *Context) String() (string, error)

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

func (*Context) ToFile

func (b *Context) ToFile(filename string) error

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

func (*Context) ToJSON

func (b *Context) ToJSON(v interface{}) error

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

func (*Context) ToXML

func (b *Context) ToXML(v interface{}) error

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

type HTTPSettings

type HTTPSettings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TLSClientConfig  *tls.Config
	Proxy            func(*http.Request) (*url.URL, error)
	Transport        http.RoundTripper
	CheckRedirect    func(req *http.Request, via []*http.Request) error
	EnableCookie     bool
	Gzip             bool
	DumpBody         bool
	Retries          int // if set to -1 means will retry forever
}

web.Client setting

Jump to

Keyboard shortcuts

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