Documentation ¶
Index ¶
- func CookieMapFromRaw(rawCookie string) map[string]string
- func InitDefaultClient(options *HTTPOptions)
- func MustProxy(proxies map[string]string) map[string]*url.URL
- type Auth
- type Body
- func Bytes(body []byte) Body
- func Form(body map[string]string) Body
- func FormBytes(body []byte) Body
- func FormString(body string) Body
- func FormValues(body map[string][]string) Body
- func JSON(body interface{}) Body
- func JSONBytes(body []byte) Body
- func JSONString(body string) Body
- func Multipart(files []*File, form map[string]string) Body
- func MultipartStream(files []*File, form map[string]string) Body
- func Reader(body io.Reader) Body
- func String(body string) Body
- func XML(body interface{}) Body
- func XMLBytes(body []byte) Body
- func XMLString(body string) Body
- type BytesBody
- type Cookies
- type File
- type HTTPOptions
- type Headers
- type JSONBody
- type M
- type MultipartBody
- type P
- type ReaderBody
- type ReaderWithCancel
- type ReqOptions
- type Response
- func Delete(url string, options *ReqOptions) (*Response, error)
- func Get(url string, options *ReqOptions) (*Response, error)
- func Head(url string, options *ReqOptions) (*Response, error)
- func Options(url string, options *ReqOptions) (*Response, error)
- func Patch(url string, options *ReqOptions) (*Response, error)
- func Post(url string, options *ReqOptions) (*Response, error)
- func Put(url string, options *ReqOptions) (*Response, error)
- func Request(method, url string, options *ReqOptions) (*Response, error)
- type Session
- func (s *Session) Delete(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Get(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Head(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Options(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Patch(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Post(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Put(url string, options *ReqOptions) (*Response, error)
- func (s *Session) Request(method string, url string, options *ReqOptions) (*Response, error)
- type StringBody
- type XMLBody
- type ZBody
- type Zhttp
- func (z *Zhttp) Delete(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Get(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Head(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) NewSession() *Session
- func (z *Zhttp) Options(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Patch(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Post(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Put(url string, options *ReqOptions) (*Response, error)
- func (z *Zhttp) Request(method, url string, options *ReqOptions) (*Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CookieMapFromRaw ¶
CookieMapFromRaw parse a cookie in string format to map[string]string
func InitDefaultClient ¶
func InitDefaultClient(options *HTTPOptions)
InitDefaultClient initialization the default zhttp client with options
Types ¶
type Body ¶
Body is used to define the body part of the http request
func FormString ¶
FormString used to create Body from string, and set form Content-Type
func FormValues ¶
FormValues used to create Body from map, and set form Content-Type The difference with form is that it supports setting multiple parameters with the same name
func JSON ¶
func JSON(body interface{}) Body
JSON used to create Body from map, struct and so on, and set json Content-Type
func JSONString ¶
JSONString used to create Body from string, and set json Content-Type
func MultipartStream ¶
MultipartStream used to create Body object Use streaming upload to prevent all files from being loaded into memory
func XML ¶
func XML(body interface{}) Body
XML used to create Body from struct, and set xml Content-Type
type Cookies ¶
Cookies is a wrapper for []*http.Cookie
func (Cookies) Get ¶
Get gets the cookie value with the given name. If there are no values associated with the name, Get returns "".
type File ¶
type File struct { // Name is the name of the file that you wish to upload. // We use this to guess the mimetype as well as pass it onto the server Name string // Contents is happy as long as you pass it a io.ReadCloser (which most file use anyways) Contents io.ReadCloser // FieldName is form field name FieldName string // Mime represents which mime should be sent along with the file. // When empty, defaults to application/octet-stream Mime string }
type HTTPOptions ¶
type HTTPOptions struct { // UserAgent allows you to set an arbitrary custom user agent UserAgent string // Cookie allows you to attach cookies to every request. Cookies map[string]string // Headers uses to set custom HTTP headers to every request // The header name is case-sensitive Headers map[string]string // Proxies is a map in the following format // *protocol* => proxy address e.g http => http://127.0.0.1:8080, Proxies map[string]*url.URL // InsecureSkipVerify is a flag that specifies if we should validate the // server's TLS certificate. It should be noted that Go's TLS verify mechanism // doesn't validate if a certificate has been revoked InsecureSkipVerify bool // RequestTimeout is the maximum amount of time a whole request(include dial / request / redirect) will wait RequestTimeout time.Duration // Timeout is the time that the client will wait between bytes sent from the server. Timeout time.Duration // DialTimeout is the maximum amount of time a dial will wait for a connect to complete DialTimeout time.Duration // TLSHandshakeTimeout specifies the maximum amount of time waiting to // wait for a TLS handshake. Zero means no timeout. TLSHandshakeTimeout time.Duration // KeepAlive specifies the interval between keep-alive // probes for an active network connection. // If zero, keep-alive probes are sent with a default value // (currently 15 seconds), if supported by the protocol and operating // system. Network protocols or operating systems that do // not support keep-alives ignore this field. // If negative, keep-alive probes are disabled. KeepAlive time.Duration // DisableKeepAlives, if true, disables HTTP keep-alives and // will only use the connection to the server for a single // HTTP request. // // This is unrelated to the similarly named TCP keep-alives. DisableKeepAlives bool // DisableCompression, if true, prevents the Transport from // requesting compression with an "Accept-Encoding: gzip" // request header when the Request contains no existing // Accept-Encoding value. If the Transport requests gzip on // its own and gets a gzipped response, it's transparently // decoded in the Response.Body. However, if the user // explicitly requested gzip it is not automatically // uncompressed. DisableCompression bool // MaxIdleConns controls the maximum number of idle (keep-alive) // connections across all hosts. Zero means no limit. MaxIdleConns int // MaxIdleConnsPerHost, if non-zero, controls the maximum idle // (keep-alive) connections to keep per-host. If zero, // DefaultMaxIdleConnsPerHost is used. MaxIdleConnsPerHost int // MaxConnsPerHost optionally limits the total number of // connections per host, including connections in the dialing, // active, and idle states. On limit violation, dials will block. // // Zero means no limit. MaxConnsPerHost int // IdleConnTimeout is the maximum amount of time an idle // (keep-alive) connection will remain idle before closing // itself. // Zero means no limit. IdleConnTimeout time.Duration // DNSCacheExpire is the timeout of dns cache , if zero, not use dns cache DNSCacheExpire time.Duration // DNSServer allows you to set an custom dns host, like 1.1.1.1:25, only effective in linux DNSServer string // NoUA is a flag that means do not set default UserAgent NoUA bool }
HTTPOptions is the options for zhttp.Zhttp, it will effective on per request
type Headers ¶
Headers is a wrapper for http.Header
func (Headers) Get ¶
Get gets the value associated with the given key. If there are no values associated with the key, Get returns "". multiple header fields with the same name will be join with ", ". It is case insensitive; textproto.CanonicalMIMEHeaderKey is used to canonicalize the provided key. To access multiple values of a key, or to use non-canonical keys, access the map directly.
type MultipartBody ¶
func (*MultipartBody) Close ¶
func (body *MultipartBody) Close()
type ReaderBody ¶
type ReaderWithCancel ¶
type ReaderWithCancel struct {
// contains filtered or unexported fields
}
func (*ReaderWithCancel) Close ¶
func (r *ReaderWithCancel) Close() error
type ReqOptions ¶
type ReqOptions struct { // RequestTimeout is the maximum amount of time a whole request(include dial / request / redirect) will wait. // if non-zero, overwrite HTTPOptions.Timeout in current request. RequestTimeout time.Duration // Timeout is the time that the client will wait between bytes sent from the server. Timeout time.Duration // ContentType allows you to set an arbitrary custom content type ContentType string // UserAgent allows you to set an arbitrary custom user agent UserAgent string // Proxies is a map in the following format // *protocol* => proxy address e.g http => http://127.0.0.1:8080, // If setted, overwrite HTTPOptions.Proxies in current request. Proxies map[string]*url.URL // DisableRedirect will disable redirect for request DisableRedirect bool // Query will be encode to query string that may be used within a GET request Query url.Values // Body is a interface{} that will eventually convert into the the body of a POST request Body Body // Cookie allows you to attach cookies to your request. // Only effective in current request Cookies map[string]string // Headers uses to set custom HTTP headers to the request // The header name is case-sensitive Headers map[string]string // Host allows you to set an arbitrary custom host Host string // HostIP allows you to set an custom dns resolution for current request. // The value should be an IP. // When proxy usable, this value does not take effect HostIP string // Auth allows you to specify a user name and password that you wish to // use when requesting the URL. It will use basic HTTP authentication // formatting the username and password in base64. Auth Auth // IsAjax is a flag that can be set to make the request appear // to be generated by browser Javascript. IsAjax bool // NoUA is a flag that means do not set default UserAgent NoUA bool }
ReqOptions is the options for single request
type Response ¶
type Response struct { StatusCode int Status string ContentLength int64 Headers Headers Body *ZBody RawResponse *http.Response // contains filtered or unexported fields }
Response is a wrapper for *http.Response
func (*Response) DumpRequest ¶
DumpRequest format the last http.Request to string. Notice, the order of headers is not strictly consistent
func (*Response) DumpResponse ¶
DumpResponse format the last http.Response to string. Notice, the order of headers is not strictly consistent
type Session ¶
Session is a client used to send http requests. Unlike Zhttp, it handle session for all requests
func NewSession ¶
func NewSession() *Session
NewSession generate an default client that will handle session for all requests
func (*Session) Delete ¶
func (s *Session) Delete(url string, options *ReqOptions) (*Response, error)
type StringBody ¶
type ZBody ¶
type ZBody struct { Err error // contains filtered or unexported fields }
ZBody is a wrapper for http.Response.ZBody
type Zhttp ¶
type Zhttp struct {
// contains filtered or unexported fields
}
func NewWithDNSCache ¶
func NewWithDNSCache(options *HTTPOptions, cache *dnscache.Cache) *Zhttp
NewWithDNSCache generate an *Zhttp client that uses an external DNSCache. This will ignore HTTPOptions.DNSCacheExpire and HTTPOptions.DNSServer
func (*Zhttp) NewSession ¶
NewSession generate an client that will handle session for all requests