Documentation ¶
Index ¶
- func SetDefaultSetting(setting HttpSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type HttpRequest
- func (this *HttpRequest) Body(data interface{}) *HttpRequest
- func (this *HttpRequest) Bytes() ([]byte, error)
- func (this *HttpRequest) Debug(isdebug bool) *HttpRequest
- func (this *HttpRequest) Header(key, value string) *HttpRequest
- func (this *HttpRequest) Param(key, value string) *HttpRequest
- func (this *HttpRequest) PostFile(formname, filename string) *HttpRequest
- func (this *HttpRequest) Response() (*http.Response, error)
- func (this *HttpRequest) SetBasicAuth(username, password string) *HttpRequest
- func (this *HttpRequest) SetCookie(cookie *http.Cookie) *HttpRequest
- func (this *HttpRequest) SetProtocolVersion(vers string) *HttpRequest
- func (this *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest
- func (this *HttpRequest) SetTLSClientConfig(config *tls.Config) *HttpRequest
- func (this *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest
- func (this *HttpRequest) SetTransport(transport http.RoundTripper) *HttpRequest
- func (this *HttpRequest) SetUserAgent(useragent string) *HttpRequest
- func (this *HttpRequest) Setting(setting HttpSettings) *HttpRequest
- func (this *HttpRequest) String() (string, error)
- func (this *HttpRequest) ToFile(filename string) error
- func (this *HttpRequest) ToJson(v interface{}) error
- func (this *HttpRequest) ToXml(v interface{}) error
- func (this *HttpRequest) UseCookieJar(jar http.CookieJar) *HttpRequest
- type HttpSettings
- type Jar
- type Options
- type PublicSuffixList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting HttpSettings)
Types ¶
type HttpRequest ¶
type HttpRequest struct {
// contains filtered or unexported fields
}
func NewRequest ¶ added in v1.0.9
func NewRequest(url, method string) *HttpRequest
func (*HttpRequest) Body ¶
func (this *HttpRequest) Body(data interface{}) *HttpRequest
Body adds request raw body. it supports string and []byte.
func (*HttpRequest) Bytes ¶
func (this *HttpRequest) Bytes() ([]byte, error)
Bytes returns the body []byte in response. it calls Response inner.
func (*HttpRequest) Debug ¶
func (this *HttpRequest) Debug(isdebug bool) *HttpRequest
Debug sets show debug or not when executing request.
func (*HttpRequest) Header ¶
func (this *HttpRequest) Header(key, value string) *HttpRequest
Header add header item string in request.
func (*HttpRequest) Param ¶
func (this *HttpRequest) Param(key, value string) *HttpRequest
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*HttpRequest) PostFile ¶
func (this *HttpRequest) PostFile(formname, filename string) *HttpRequest
func (*HttpRequest) Response ¶
func (this *HttpRequest) Response() (*http.Response, error)
Response executes request client gets response mannually.
func (*HttpRequest) SetBasicAuth ¶
func (this *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) SetCookie ¶
func (this *HttpRequest) SetCookie(cookie *http.Cookie) *HttpRequest
SetCookie add cookie into request.
func (*HttpRequest) SetProtocolVersion ¶
func (this *HttpRequest) SetProtocolVersion(vers string) *HttpRequest
Set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*HttpRequest) SetProxy ¶
func (this *HttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HttpRequest
Set 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 (this *HttpRequest) SetTLSClientConfig(config *tls.Config) *HttpRequest
SetTLSClientConfig sets tls connection configurations if visiting https url.
func (*HttpRequest) SetTimeout ¶
func (this *HttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *HttpRequest
SetTimeout sets connect time out and read-write time out for Request.
func (*HttpRequest) SetTransport ¶
func (this *HttpRequest) SetTransport(transport http.RoundTripper) *HttpRequest
Set transport to
func (*HttpRequest) SetUserAgent ¶
func (this *HttpRequest) SetUserAgent(useragent string) *HttpRequest
SetUserAgent sets User-Agent header field
func (*HttpRequest) Setting ¶
func (this *HttpRequest) Setting(setting HttpSettings) *HttpRequest
重置http设置
func (*HttpRequest) String ¶
func (this *HttpRequest) String() (string, error)
String returns the body string in response. it calls Response inner.
func (*HttpRequest) ToFile ¶
func (this *HttpRequest) ToFile(filename string) error
ToFile saves the body data in response to one file. it calls Response inner.
func (*HttpRequest) ToJson ¶
func (this *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 (this *HttpRequest) ToXml(v interface{}) error
ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.
func (*HttpRequest) UseCookieJar ¶
func (this *HttpRequest) UseCookieJar(jar http.CookieJar) *HttpRequest
SetEnableCookie sets cookiejar
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 }
HttpSettings
type Jar ¶
Jar implements the http.CookieJar interface from the net/http package.
type Options ¶
type Options struct { // PublicSuffixList is the public suffix list that determines whether // an HTTP server can set a cookie for a domain. // // A nil value is valid and may be useful for testing but it is not // secure: it means that the HTTP server for foo.co.uk can set a cookie // for bar.co.uk. PublicSuffixList PublicSuffixList }
Options are the options for creating a new Jar.
type PublicSuffixList ¶
type PublicSuffixList interface { // PublicSuffix returns the public suffix of domain. // // TODO: specify which of the caller and callee is responsible for IP // addresses, for leading and trailing dots, for case sensitivity, and // for IDN/Punycode. PublicSuffix(domain string) string // String returns a description of the source of this public suffix // list. The description will typically contain something like a time // stamp or version number. String() string }
PublicSuffixList provides the public suffix of a domain. For example:
- the public suffix of "example.com" is "com",
- the public suffix of "foo1.foo2.foo3.co.uk" is "co.uk", and
- the public suffix of "bar.pvt.k12.ma.us" is "pvt.k12.ma.us".
Implementations of PublicSuffixList must be safe for concurrent use by multiple goroutines.
An implementation that always returns "" is valid and may be useful for testing but it is not secure: it means that the HTTP server for foo.com can set a cookie for bar.com.
A public suffix list implementation is in the package golang.org/x/net/publicsuffix.