httplib

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeoutDialer

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

func TimeoutDialerContext

func TimeoutDialerContext(cTimeout, rwTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error)

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 NewLibRequest

func NewLibRequest(rawUrl, method string) *HTTPRequest

func Post

func Post(url string) *HTTPRequest

func Put

func Put(url string) *HTTPRequest

func (*HTTPRequest) DoRequest

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

func (*HTTPRequest) GetDumpRequest

func (h *HTTPRequest) GetDumpRequest() []byte

func (*HTTPRequest) GetRequest

func (h *HTTPRequest) GetRequest() *http.Request

func (*HTTPRequest) PostFile

func (h *HTTPRequest) PostFile(fieldname, filename string) *HTTPRequest

func (*HTTPRequest) RespToByte

func (h *HTTPRequest) RespToByte() ([]byte, error)

func (*HTTPRequest) RespToFile

func (h *HTTPRequest) RespToFile(filename string) error

func (*HTTPRequest) RespToJSON

func (h *HTTPRequest) RespToJSON(v interface{}) error

func (*HTTPRequest) RespToString

func (h *HTTPRequest) RespToString() (string, error)

func (*HTTPRequest) RespToXML

func (h *HTTPRequest) RespToXML(v interface{}) error

func (*HTTPRequest) Response

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

func (*HTTPRequest) SetBasicAuth

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

func (*HTTPRequest) SetBody

func (h *HTTPRequest) SetBody(data interface{}) *HTTPRequest

func (*HTTPRequest) SetCheckRedirect

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

func (*HTTPRequest) SetCookie

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

func (*HTTPRequest) SetDebug

func (h *HTTPRequest) SetDebug(isdebug bool) *HTTPRequest

func (*HTTPRequest) SetDumpBody

func (h *HTTPRequest) SetDumpBody(dumpBody bool) *HTTPRequest

func (*HTTPRequest) SetEnableCookie

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

func (*HTTPRequest) SetHeader

func (h *HTTPRequest) SetHeader(key, value string) *HTTPRequest

func (*HTTPRequest) SetHost

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

func (*HTTPRequest) SetJSONBody

func (h *HTTPRequest) SetJSONBody(obj interface{}) (*HTTPRequest, error)

func (*HTTPRequest) SetKeepAlive

func (h *HTTPRequest) SetKeepAlive(enable bool) *HTTPRequest

func (*HTTPRequest) SetMaxIdleConnsPerHost

func (h *HTTPRequest) SetMaxIdleConnsPerHost(n int) *HTTPRequest

SetMaxIdleConnsPerHost 可根据并发设置,一般默认即可

func (*HTTPRequest) SetParam

func (h *HTTPRequest) SetParam(key, value string) *HTTPRequest

func (*HTTPRequest) SetParams

func (h *HTTPRequest) SetParams(v interface{}) (*HTTPRequest, error)

SetParams json 格式的 struct 直接转换成 k v 字符串, 作为表单提交

func (*HTTPRequest) SetProtocolVersion

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

func (*HTTPRequest) SetProxy

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

func (*HTTPRequest) SetRetries

func (h *HTTPRequest) SetRetries(retries int) *HTTPRequest

func (*HTTPRequest) SetTLSClientConfig

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

func (*HTTPRequest) SetTimeout

func (h *HTTPRequest) SetTimeout(cTimeout, rwTimeout time.Duration) *HTTPRequest

func (*HTTPRequest) SetTransport

func (h *HTTPRequest) SetTransport(tran http.Transport) *HTTPRequest

SetTransport 自定义 transport

func (*HTTPRequest) SetUserAgent

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

func (*HTTPRequest) Setting

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

func (*HTTPRequest) WithContext added in v0.2.10

func (h *HTTPRequest) WithContext(ctx context.Context) *HTTPRequest

func (*HTTPRequest) XMLBody

func (h *HTTPRequest) XMLBody(obj interface{}) (*HTTPRequest, error)

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 // 如果设置 -1 则一直重试
	KeepAlive           bool
	MaxIdleConnsPerHost int // 默认 2
}

type Params

type Params map[string]interface{}

Jump to

Keyboard shortcuts

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