Documentation
¶
Index ¶
- type Client
- func (c *Client) Get() (*Response, error)
- func (c *Client) PatchJSON(data interface{}) (*Response, error)
- func (c *Client) PostForm(values url.Values) (*Response, error)
- func (c *Client) PostJSON(data interface{}) (*Response, error)
- func (c *Client) String() string
- func (c *Client) WithAuthorization(authorization string) *Client
- func (c *Client) WithCacheHeaders(etagHeader, lastModifiedHeader string) *Client
- func (c *Client) WithCookie(cookie string) *Client
- func (c *Client) WithCredentials(username, password string) *Client
- func (c *Client) WithCustomHeaders(customHeaders map[string]string) *Client
- func (c *Client) WithProxy() *Client
- func (c *Client) WithUserAgent(userAgent string) *Client
- func (c *Client) WithoutRedirects() *Client
- type Response
- func (r *Response) BodyAsString() string
- func (r *Response) EnsureUnicodeBody() (err error)
- func (r *Response) HasServerFailure() bool
- func (r *Response) IsModified(etag, lastModified string) bool
- func (r *Response) IsNotAuthorized() bool
- func (r *Response) IsNotFound() bool
- func (r *Response) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { ClientTimeout int ClientMaxBodySize int64 ClientProxyURL string AllowSelfSignedCertificates bool // contains filtered or unexported fields }
Client builds and executes HTTP requests.
func NewClientWithConfig ¶
NewClientWithConfig initializes a new HTTP client with application config options.
func (*Client) WithAuthorization ¶
WithAuthorization defines the authorization HTTP header value.
func (*Client) WithCacheHeaders ¶
WithCacheHeaders defines caching headers.
func (*Client) WithCookie ¶
WithCookie defines the Cookies to use for HTTP requests.
func (*Client) WithCredentials ¶
WithCredentials defines the username/password for HTTP Basic authentication.
func (*Client) WithCustomHeaders ¶
WithCustomHeaders defines custom HTTP headers.
func (*Client) WithUserAgent ¶
WithUserAgent defines the User-Agent header to use for HTTP requests.
func (*Client) WithoutRedirects ¶
WithoutRedirects disables HTTP redirects.
type Response ¶
type Response struct { Body io.Reader StatusCode int EffectiveURL string LastModified string ETag string Expires string ContentType string ContentLength int64 }
Response wraps a server response.
func (*Response) BodyAsString ¶
BodyAsString returns the response body as string.
func (*Response) EnsureUnicodeBody ¶
EnsureUnicodeBody makes sure the body is encoded in UTF-8.
If a charset other than UTF-8 is detected, we convert the document to UTF-8. This is used by the scraper and feed readers.
Do not forget edge cases:
- Feeds with encoding specified only in Content-Type header and not in XML document - Feeds with encoding specified in both places - Feeds with encoding specified only in XML document and not in HTTP header - Feeds with wrong encoding defined and already in UTF-8
func (*Response) HasServerFailure ¶
HasServerFailure returns true if the status code represents a failure.
func (*Response) IsModified ¶
IsModified returns true if the resource has been modified.
func (*Response) IsNotAuthorized ¶
IsNotAuthorized returns true if the resource require authentication.
func (*Response) IsNotFound ¶
IsNotFound returns true if the resource doesn't exist anymore.