func (c *Client) Do(req *http.Request, path string) (*http.Response, error) {
	if c.params.User != "" {
		userPass := c.params.User + ":" + c.params.Password
		authBasic := base64.StdEncoding.EncodeToString([]byte(userPass))
		req.Header.Set("Authorization", "Basic "+authBasic)
	}

	// Prepare the request.
	if !strings.HasPrefix(path, "/") {
		return nil, errgo.Newf("path %q is not absolute", path)
	}
	for k, vv := range c.header {
		req.Header[k] = append(req.Header[k], vv...)
	}

	// Set the user-agent if one isn't supplied
	if userAgent := req.Header.Get(userAgentKey); userAgent == "" {
		req.Header.Set(userAgentKey, c.userAgentValue)
	}

	u, err := url.Parse(c.params.URL + "/" + apiVersion + path)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	if c.channel != params.NoChannel {
		values := u.Query()
		values.Set("channel", string(c.channel))
		u.RawQuery = values.Encode()
	}
	req.URL = u

	// Send the request.
	resp, err := c.bclient.Do(req)
	if err != nil {
		return nil, errgo.Mask(err, isAPIError)
	}

	if resp.StatusCode == http.StatusOK {
		return resp, nil
	}
	defer resp.Body.Close()

	// Parse the response error.
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errgo.Notef(err, "cannot read response body")
	}

	if resp.Header.Get("Content-Type") != "application/json" {
		return nil, errgo.Newf("unexpected response status from server: %v", resp.Status)
	}
	var perr params.Error
	if err := json.Unmarshal(data, &perr); err != nil {
		return nil, errgo.Notef(err, "cannot unmarshal error response %q", sizeLimit(data))
	}
	if perr.Message == "" {
		return nil, errgo.Newf("error response with empty message %s", sizeLimit(data))
	}
	return nil, &perr
}
// Do makes an arbitrary request to the charm store.
// It adds appropriate headers to the given HTTP request,
// sends it to the charm store, and returns the resulting
// response. Do never returns a response with a status
// that is not http.StatusOK.
//
// The URL field in the request is ignored and overwritten.
//
// This is a low level method - more specific Client methods
// should be used when possible.
//
// Note that if a body is supplied in the request, it should
// implement io.Seeker.
//
// Any error returned from the underlying httpbakery.Do
// request will have an unchanged error cause.
Do makes an arbitrary request to the charm store.
It adds appropriate headers to the given HTTP request,
sends it to the charm store, and returns the resulting
response. Do never returns a response with a status
that is not http.StatusOK.

The URL field in the request is ignored and overwritten.

This is a low level method - more specific Client methods
should be used when possible.

Note that if a body is supplied in the request, it should
implement io.Seeker.

Any error returned from the underlying httpbakery.Do
request will have an unchanged error cause.
// Do makes an arbitrary request to the charm store . // It adds appropriate headers to the given HTTP request // sends it to the charm store and returns the resulting // response . Do never returns a response with a status // that is not http . StatusOK . // // The URL field in the request is ignored and overwritten . // // This is a low level method - more specific Client methods // should be used when possible . // // Note that if a body is supplied in the request it should // implement io . Seeker . // // Any error returned from the underlying httpbakery . Do // request will have an unchanged error cause .
func (c *Client) Do(req *http.Request, path string) (*http.Response, error) {
	if c.params.User != "" {
		userPass := c.params.User + ":" + c.params.Password
		authBasic := base64.StdEncoding.EncodeToString([]byte(userPass))
		req.Header.Set("Authorization", "Basic "+authBasic)
	}
	if !strings.HasPrefix(path, "/") {
		return nil, errgo.Newf("path %q is not absolute", path)
	}
	for k, vv := range c.header {
		req.Header[k] = append(req.Header[k], vv...)
	}
	if userAgent := req.Header.Get(userAgentKey); userAgent == "" {
		req.Header.Set(userAgentKey, c.userAgentValue)
	}
	u, err := url.Parse(c.params.URL + "/" + apiVersion + path)
	if err != nil {
		return nil, errgo.Mask(err)
	}
	if c.channel != params.NoChannel {
		values := u.Query()
		values.Set("channel", string(c.channel))
		u.RawQuery = values.Encode()
	}
	req.URL = u
	resp, err := c.bclient.Do(req)
	if err != nil {
		return nil, errgo.Mask(err, isAPIError)
	}
	if resp.StatusCode == http.StatusOK {
		return resp, nil
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errgo.Notef(err, "cannot read response body")
	}
	if resp.Header.Get("Content-Type") != "application/json" {
		return nil, errgo.Newf("unexpected response status from server: %v", resp.Status)
	}
	var perr params.Error
	if err := json.Unmarshal(data, &perr); err != nil {
		return nil, errgo.Notef(err, "cannot unmarshal error response %q", sizeLimit(data))
	}
	if perr.Message == "" {
		return nil, errgo.Newf("error response with empty message %s", sizeLimit(data))
	}
	return nil, &perr
}
func ( c * Client ) Do ( req * http . Request , path string ) ( * http . Response , error ) { if c . params . User != " " { userPass := c . params . User + " " + c . params . Password authBasic := base64 . StdEncoding . EncodeToString ( [ ] byte ( userPass ) ) req . Header . Set ( " " , " " + authBasic ) } if ! strings . HasPrefix ( path , " " ) { return nil , errgo . Newf ( " " , path ) } for k , vv := range c . header { req . Header [ k ] = append ( req . Header [ k ] , vv ... ) } if userAgent := req . Header . Get ( userAgentKey ) ; userAgent == " " { req . Header . Set ( userAgentKey , c . userAgentValue ) } u , err := url . Parse ( c . params . URL + " " + apiVersion + path ) if err != nil { return nil , errgo . Mask ( err ) } if c . channel != params . NoChannel { values := u . Query ( ) values . Set ( " " , string ( c . channel ) ) u . RawQuery = values . Encode ( ) } req . URL = u resp , err := c . bclient . Do ( req ) if err != nil { return nil , errgo . Mask ( err , isAPIError ) } if resp . StatusCode == http . StatusOK { return resp , nil } defer resp . Body . Close ( ) data , err := ioutil . ReadAll ( resp . Body ) if err != nil { return nil , errgo . Notef ( err , " " ) } if resp . Header . Get ( " " ) != " " { return nil , errgo . Newf ( " " , resp . Status ) } var perr params . Error if err := json . Unmarshal ( data , & perr ) ; err != nil { return nil , errgo . Notef ( err , " " , sizeLimit ( data ) ) } if perr . Message == " " { return nil , errgo . Newf ( " " , sizeLimit ( data ) ) } return nil , & perr }
Do makes an arbitrary request to the charm store.
Do makes an arbitrary request to the charm store .
// Prepare the request. // Set the user-agent if one isn't supplied // Send the request. // Parse the response error.