Documentation
¶
Index ¶
- Constants
- Variables
- func Cookies(raw interface{}) []*http.Cookie
- func FileCacheDir(s string) fileCacheDir
- func MarshalRequest(req *http.Request) ([]byte, error)
- func MarshalResponse(resp *http.Response) ([]byte, error)
- func MemoryCache() memoryCacheDir
- func RequestHash(r *http.Request) (string, error)
- func TryCharset(r io.Reader, contentType string) (io.Reader, string, error)
- func TryHTMLCharset(r io.Reader) (io.Reader, string, error)
- func URL(raw interface{}) *url.URL
- func UnmarshalRequest(data []byte) (req *http.Request, err error)
- func UnmarshalResponse(data []byte) (resp *http.Response, err error)
- type Cache
- type Client
- func (c *Client) AddCookies(u *url.URL, cookies []*http.Cookie) *Client
- func (c *Client) AddRootCert(cert *x509.Certificate) *Client
- func (c *Client) GetCookie(u *url.URL, name string) *http.Cookie
- func (c *Client) GetCookieJar() http.CookieJar
- func (c *Client) NewRequest() *Request
- func (c *Client) NoRedirect() *Client
- func (c *Client) Process(req *http.Request) (*http.Response, error)
- func (c *Client) SetCache(cache Cache) *Client
- func (c *Client) SetCheckRedirect(f func(req *http.Request, via []*http.Request) error) *Client
- func (c *Client) SetCookieJar(jar http.CookieJar) *Client
- func (c *Client) SetDial(dial func(network, addr string) (net.Conn, error)) *Client
- func (c *Client) SetDialContext(dial func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
- func (c *Client) SetDialTLS(dial func(network, addr string) (net.Conn, error)) *Client
- func (c *Client) SetKeepAlives(enable bool) *Client
- func (c *Client) SetLogLevel(l logLevel) *Client
- func (c *Client) SetLogger(w io.Writer) *Client
- func (c *Client) SetProxyFromEnvironment(u bool) *Client
- func (c *Client) SetProxyFunc(proxy func(*http.Request) (*url.URL, error)) *Client
- func (c *Client) SetProxyURL(u *url.URL) *Client
- func (c *Client) SetProxyURLByStr(rawurl string) *Client
- func (c *Client) SetSkipVerify(b bool) *Client
- func (c *Client) SetTLSClientConfig(config *tls.Config) *Client
- func (c *Client) SetTimeout(timeout time.Duration) *Client
- func (c *Client) WithCookieJar() *Client
- func (c *Client) WithLogger() *Client
- func (c *Client) WithSystemCertPool() *Client
- type Request
- func (r *Request) AddCookies(cookies []*http.Cookie) *Request
- func (r *Request) AddForm(param, value string) *Request
- func (r *Request) AddFormIfNot(param, value string) *Request
- func (r *Request) AddForms(param string, value []string) *Request
- func (r *Request) AddHeader(param, value string) *Request
- func (r *Request) AddHeaderIfNot(param, value string) *Request
- func (r *Request) AddHeaders(param string, value []string) *Request
- func (r *Request) AddPathIfNot(param, value string) *Request
- func (r *Request) AddQuery(param, value string) *Request
- func (r *Request) AddQueryIfNot(param, value string) *Request
- func (r *Request) AddQuerys(param string, value []string) *Request
- func (r *Request) Client() *Client
- func (r *Request) Clone() *Request
- func (r *Request) Delete(url string) (*Response, error)
- func (r *Request) Do() (*Response, error)
- func (r *Request) Get(url string) (*Response, error)
- func (r *Request) GetURL(rawurl string) *url.URL
- func (r *Request) Head(url string) (*Response, error)
- func (r *Request) Message() string
- func (r *Request) MessageHead() string
- func (r *Request) NoCache() *Request
- func (r *Request) Options(url string) (*Response, error)
- func (r *Request) Patch(url string) (*Response, error)
- func (r *Request) Post(url string) (*Response, error)
- func (r *Request) Put(url string) (*Response, error)
- func (r *Request) RawRequest() (*http.Request, error)
- func (r *Request) SetAuthToken(token string) *Request
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetBody(body io.Reader) *Request
- func (r *Request) SetCharset(transformer transform.Transformer) *Request
- func (r *Request) SetCharsetWithStr(cs string) *Request
- func (r *Request) SetContentType(contentType string) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetDeadline(d time.Time) *Request
- func (r *Request) SetDiscardResponse(discard bool) *Request
- func (r *Request) SetFile(param, fileName, contentType string, reader io.Reader) *Request
- func (r *Request) SetForm(param, value string) *Request
- func (r *Request) SetHeader(param, value string) *Request
- func (r *Request) SetJSON(i interface{}) *Request
- func (r *Request) SetMethod(method string) *Request
- func (r *Request) SetPath(param, value string) *Request
- func (r *Request) SetQuery(param, value string) *Request
- func (r *Request) SetTimeout(timeout time.Duration) *Request
- func (r *Request) SetURL(u *url.URL) *Request
- func (r *Request) SetURLByStr(rawurl string) *Request
- func (r *Request) SetUserAgent(ua string) *Request
- func (r *Request) SetXML(i interface{}) *Request
- func (r *Request) String() string
- func (r *Request) Trace(url string) (*Response, error)
- type Response
- func (r *Response) Body() []byte
- func (r *Response) ContentType() string
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) Header() http.Header
- func (r *Response) Location() *url.URL
- func (r *Response) MarshalText() ([]byte, error)
- func (r *Response) Message() string
- func (r *Response) MessageHead() string
- func (r *Response) RawBody() io.Reader
- func (r *Response) RawResponse() *http.Response
- func (r *Response) RecvAt() time.Time
- func (r *Response) SendAt() time.Time
- func (r *Response) Size() int
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() string
- func (r *Response) Time() time.Duration
- func (r *Response) UnarshalText(data []byte) error
- func (r *Response) WriteFile(file string) error
Constants ¶
const ( // LogIgnore is ignore all information LogIgnore logLevel = iota // LogError is show Errors Only LogError // LogInfo is show basic information LogInfo // LogMessageHead is show header information LogMessageHead // LogMessageAll is show all information LogMessageAll )
const ( MethodGet = "GET" MethodHead = "HEAD" MethodPost = "POST" MethodPut = "PUT" MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" MethodConnect = "CONNECT" MethodOptions = "OPTIONS" MethodTrace = "TRACE" MimeJSON = "application/json" + charsetUTF8 MimeXML = "application/xml" + charsetUTF8 MimeTextPlain = "text/plain" + charsetUTF8 MimeOctetStream = "application/octet-stream" + charsetUTF8 MimeURLEncoded = "application/x-www-form-urlencoded" + charsetUTF8 MimeFormData = "multipart/form-data" + charsetUTF8 HeaderUserAgent = "User-Agent" HeaderAccept = "Accept" HeaderContentType = "Content-Type" HeaderContentLength = "Content-Length" HeaderContentEncoding = "Content-Encoding" HeaderAuthorization = "Authorization" )
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
Variables ¶
var ( ErrNoRedirect = errors.New("No Redirect") ErrNotTransport = errors.New("not a *http.Transport") )
var ( DefaultPrefix = "REQUESTS" DefaultVersion = "1.0" DefaultUserAgentValue = "Mozilla/5.0 (compatible; " + DefaultPrefix + "/" + DefaultVersion + "; +https://github.com/wzshiming/requests)" )
Default
var ErrNotExist = errors.New("not exist")
Functions ¶
func FileCacheDir ¶
func FileCacheDir(s string) fileCacheDir
func MarshalRequest ¶ added in v0.0.2
MarshalRequest returns text of the request
func MarshalResponse ¶ added in v0.0.2
MarshalRequest returns text of the request
func MemoryCache ¶
func MemoryCache() memoryCacheDir
func TryCharset ¶
TryCharset try charset
func TryHTMLCharset ¶ added in v0.0.2
TryHTMLCharset try html charset
func UnmarshalRequest ¶ added in v0.0.2
UnmarshalRequest reads and returns an HTTP request from data.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client contains basic
func (*Client) AddCookies ¶
AddCookies adds cookie to the client.
func (*Client) AddRootCert ¶
func (c *Client) AddRootCert(cert *x509.Certificate) *Client
AddRootCert adds one or more root certificates into requests client
func (*Client) GetCookieJar ¶
GetCookieJar gets cookie jar.
func (*Client) NewRequest ¶
NewRequest creates a request instance.
func (*Client) SetCheckRedirect ¶
SetCheckRedirect sets specifies the policy for handling redirects
func (*Client) SetCookieJar ¶
SetCookieJar sets cookie jar.
func (*Client) SetDialContext ¶
func (c *Client) SetDialContext(dial func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
SetDialContext sets DialContext.
func (*Client) SetDialTLS ¶
SetDialTLS sets DialTLS.
func (*Client) SetKeepAlives ¶
SetKeepAlives sets the keep alives.
func (*Client) SetLogLevel ¶
SetLogLevel sets log level.
func (*Client) SetProxyFromEnvironment ¶
SetProxyFromEnvironment sets the Proxy URL.
func (*Client) SetProxyFunc ¶
SetProxyFunc sets the Proxy function.
func (*Client) SetProxyURL ¶
SetProxyURL sets the Proxy URL.
func (*Client) SetProxyURLByStr ¶
SetProxyURLByStr sets the Proxy URL.
func (*Client) SetSkipVerify ¶
SetSkipVerify sets skip ca verify
func (*Client) SetTLSClientConfig ¶
SetTLSClientConfig sets TLSClientConfig.
func (*Client) SetTimeout ¶
SetTimeout sets timeout for request raised from client.
func (*Client) WithCookieJar ¶
WithCookieJar with default cookie jar.
func (*Client) WithSystemCertPool ¶
WithSystemCertPool sets system cert poll
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request type is used to compose and send individual request from client
func (*Request) AddCookies ¶
AddCookies adds cookie to the client.
func (*Request) AddFormIfNot ¶
AddFormIfNot adds from field and its value in the current request if not.
func (*Request) AddHeaderIfNot ¶
AddHeaderIfNot adds header field and its value in the current request if not.
func (*Request) AddHeaders ¶
AddHeaders adds header field and its value in the current request.
func (*Request) AddPathIfNot ¶
AddPathIfNot adds path parameter and its value in the current request if not.
func (*Request) AddQueryIfNot ¶
AddQueryIfNot adds query field and its value in the current request if not.
func (*Request) MessageHead ¶
MessageHead returns the HTTP request header information
func (*Request) SetAuthToken ¶
SetAuthToken sets bearer auth token header in the HTTP request.
func (*Request) SetBasicAuth ¶
SetBasicAuth sets basic authentication header in the HTTP request.
func (*Request) SetCharset ¶ added in v0.0.2
func (r *Request) SetCharset(transformer transform.Transformer) *Request
func (*Request) SetCharsetWithStr ¶ added in v0.0.2
func (*Request) SetContentType ¶
SetContentType sets content type header in the HTTP request.
func (*Request) SetContext ¶
SetContext sets context.Context for current Request.
func (*Request) SetDeadline ¶
SetDeadline sets deadline for current Request.
func (*Request) SetDiscardResponse ¶
SetDiscardResponse sets unread the response body.
func (*Request) SetTimeout ¶
SetTimeout sets timeout for current Request.
func (*Request) SetURLByStr ¶
SetURLByStr sets URL in the client instance.
func (*Request) SetUserAgent ¶
SetUserAgent sets user agent header in the HTTP request.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is an object represents executed request and its values.
func (*Response) ContentType ¶
ContentType returns HTTP response content type
func (*Response) MarshalText ¶ added in v0.0.2
func (*Response) MessageHead ¶
MessageHead returns the HTTP response header information
func (*Response) RawResponse ¶
func (*Response) RecvAt ¶ added in v0.0.2
RecvAt returns when response got recv from server for the request.
func (*Response) SendAt ¶ added in v0.0.2
SendAt returns when response got send from server for the request.
func (*Response) StatusCode ¶
StatusCode returns the HTTP status code for the executed request.
func (*Response) Time ¶
Time returns the time of HTTP response time that from request we sent and received a request.