httplib

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 HTTPRequest

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

func Delete

func Delete(url string) *HTTPRequest

func Get

func Get(url string) *HTTPRequest
func Head(url string) *HTTPRequest

func NewRequest

func NewRequest(rawurl, method string) *HTTPRequest

func Post

func Post(url string) *HTTPRequest

func Put

func Put(url string) *HTTPRequest

func (*HTTPRequest) Body

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

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

func (*HTTPRequest) Bytes

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

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

func (*HTTPRequest) Debug

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

Debug sets show debug or not when executing request.

func (*HTTPRequest) Delete

func (b *HTTPRequest) Delete(url string) *HTTPRequest

func (*HTTPRequest) DoRequest

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

DoRequest will do the client.Do

func (*HTTPRequest) Get

func (b *HTTPRequest) Get(url string) *HTTPRequest

func (*HTTPRequest) Head

func (b *HTTPRequest) Head(url string) *HTTPRequest

func (*HTTPRequest) Header

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

Header add header item string in request.

func (*HTTPRequest) JSONBody

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

JSONBody adds request raw body encoding by JSON.

func (*HTTPRequest) NewRequest

func (b *HTTPRequest) NewRequest(rawurl, method string) *HTTPRequest

func (*HTTPRequest) Param

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

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

func (*HTTPRequest) Post

func (b *HTTPRequest) Post(url string) *HTTPRequest

func (*HTTPRequest) PostFile

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

PostFile add a post file to the request

func (*HTTPRequest) Put

func (b *HTTPRequest) Put(url string) *HTTPRequest

func (*HTTPRequest) Response

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

Response executes request client gets response mannually.

func (*HTTPRequest) SetBasicAuth

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

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

func (*HTTPRequest) SetCheckRedirect

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

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 (*HTTPRequest) SetCookie

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

SetCookie add cookie into request.

func (*HTTPRequest) SetEnableCookie

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

SetEnableCookie sets enable/disable cookiejar

func (*HTTPRequest) SetHost

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

SetHost set the request host

func (*HTTPRequest) SetProtocolVersion

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

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

func (*HTTPRequest) SetProxy

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

SetProxy set the http proxy example:

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

func (*HTTPRequest) SetTLSClientConfig

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

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*HTTPRequest) SetTimeout

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

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

func (*HTTPRequest) SetTransport

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

SetTransport set the setting transport

func (*HTTPRequest) SetUserAgent

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

SetUserAgent sets User-Agent header field

func (*HTTPRequest) Setting

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

Setting Change request settings

func (*HTTPRequest) String

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

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

func (*HTTPRequest) ToFile

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

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

func (*HTTPRequest) ToJSON

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

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

func (*HTTPRequest) ToXML

func (b *HTTPRequest) 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
}

Jump to

Keyboard shortcuts

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