Documentation ¶
Index ¶
- Variables
- func DontFollow(req *http.Request, via []*http.Request) error
- func MarshalJSON(data interface{}) io.ReadSeeker
- func New(method, uri string, data io.Reader, headers ...map[string]string) (*http.Request, error)
- func NewClient(log *util.Logger) *http.Client
- func NewTripper(log *util.Logger, base http.RoundTripper) http.RoundTripper
- func ReadBody(resp *http.Response) ([]byte, error)
- func ResponseError(resp *http.Response) error
- type Helper
- type InterceptResult
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( FormContent = "application/x-www-form-urlencoded" JSONContent = "application/json" PlainContent = "text/plain" XMLContent = "application/xml" // URLEncoding specifies application/x-www-form-urlencoded URLEncoding = map[string]string{"Content-Type": FormContent} // JSONEncoding specifies application/json JSONEncoding = map[string]string{ "Content-Type": JSONContent, "Accept": JSONContent, } // AcceptJSON accepting application/json AcceptJSON = map[string]string{ "Accept": JSONContent, } // XMLEncoding specifies application/xml XMLEncoding = map[string]string{ "Content-Type": XMLContent, "Accept": XMLContent, } // AcceptXML accepting application/xml AcceptXML = map[string]string{ "Accept": XMLContent, } )
var ( LogHeaders bool LogMaxLen = 1024 * 8 )
var Timeout = 10 * time.Second
Timeout is the default request timeout used by the Helper
Functions ¶
func DontFollow ¶
DontFollow is a redirect policy that does not follow redirects
func MarshalJSON ¶
func MarshalJSON(data interface{}) io.ReadSeeker
MarshalJSON marshals JSON into an io.ReadSeeker
func NewTripper ¶
func NewTripper(log *util.Logger, base http.RoundTripper) http.RoundTripper
NewTripper creates a logging roundtrip handler
func ReadBody ¶
ReadBody reads HTTP response and returns error on response codes other than HTTP 2xx. It closes the request body after reading.
func ResponseError ¶
ResponseError turns an HTTP status code into an error
Types ¶
type Helper ¶
Helper provides utility primitives
func (*Helper) DoJSON ¶
DoJSON executes HTTP request and decodes JSON response. It returns a StatusError on response codes other than HTTP 2xx.
type InterceptResult ¶
func InterceptRedirect ¶
func InterceptRedirect(param string, stop bool) (func(req *http.Request, via []*http.Request) error, InterceptResult)
InterceptRedirect captures a redirect url parameter
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError indicates unsuccessful http response
func NewStatusError ¶
func NewStatusError(resp *http.Response) StatusError
NewStatusError create new StatusError for given response
func (StatusError) Error ¶
func (e StatusError) Error() string
func (StatusError) HasStatus ¶
func (e StatusError) HasStatus(codes ...int) bool
HasStatus returns true if the response's status code matches any of the given codes
func (StatusError) Response ¶
func (e StatusError) Response() *http.Response
Response returns the response with the unexpected error
func (StatusError) StatusCode ¶
func (e StatusError) StatusCode() int
StatusCode returns the response's status code