Пример #1
0
func (signer *DefaultRoundTripSigner) RoundTrip(req *http.Request) (*http.Response, error) {
	if signer.Transport == nil {
		return nil, errors.New("Invalid transport provided")
	}

	reqCopy := http.Request(*req)
	err := signer.SignHttpRequest(&reqCopy)
	if err != nil {
		return nil, err
	}

	resp, err := signer.Transport.RoundTrip(&reqCopy)
	return resp, err
}
Пример #2
0
func NewClient(options *Options) *Client {
	req := newHTTPClient().SetBasicAuth(options.Username, options.Password)
	req = req.RedirectPolicy(func(r gorequest.Request, via []gorequest.Request) error {
		// perform BasicAuth on each redirect request.
		// (requests are cookie-less; so we need to keep re-auth-ing again)
		httpReq := http.Request(*r)
		httpReq.SetBasicAuth(options.Username, options.Password)
		log.Println("REDIRECT", r, options.Username, options.Password)
		return nil
	})
	return &Client{
		req:     req,
		options: options,
		baseURL: options.BaseAPIURL,
	}
}