// MakeRequest Executes an HTTP request using a session token
MakeRequest Executes an HTTP request using a session token
// MakeRequest Executes an HTTP request using a session token
func (conn *RestConnection) MakeRequest(method string, url string, payload io.Reader, contentType string) (result *io.ReadCloser, err error) {
	endpoint := fmt.Sprintf("%s/api/v%s%s", conn.Host, conn.APIVersion, url)
	req, err := http.NewRequest(method, endpoint, payload)
	if err != nil {
		return nil, err
	}
	req.Header.Add("Authorization", "Bearer "+conn.AccessToken)
	if contentType != "" {
		req.Header.Add("Content-Type", contentType)
	}
	req.Header.Add("User-Agent", "Skuid-CLI/"+VERSION)
	resp, err := getClientForProxyURL(conn.MetadataServiceProxy).Do(req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == 401 {
		defer resp.Body.Close()
		conn.AccessToken = ""
		refreshErr := conn.Refresh()
		if refreshErr == nil && conn.AccessToken != "" {
			newResp, newErr := getClientForProxyURL(conn.MetadataServiceProxy).Do(req)
			if newErr != nil {
				return nil, newErr
			}
			if newResp.StatusCode != 200 {
				defer newResp.Body.Close()
				return nil, httperror.New(newResp.Status, newResp.Body)
			}
			return &newResp.Body, nil
		}
	}
	if resp.StatusCode != 200 {
		defer resp.Body.Close()
		return nil, httperror.New(resp.Status, resp.Body)
	}
	return &resp.Body, nil
}
func ( conn * RestConnection ) MakeRequest ( method string , url string , payload io . Reader , contentType string ) ( result * io . ReadCloser , err error ) { endpoint := fmt . Sprintf ( " " , conn . Host , conn . APIVersion , url ) req , err := http . NewRequest ( method , endpoint , payload ) if err != nil { return nil , err } req . Header . Add ( " " , " " + conn . AccessToken ) if contentType != " " { req . Header . Add ( " " , contentType ) } req . Header . Add ( " " , " " + VERSION ) resp , err := getClientForProxyURL ( conn . MetadataServiceProxy ) . Do ( req ) if err != nil { return nil , err } if resp . StatusCode == 401 { defer resp . Body . Close ( ) conn . AccessToken = " " refreshErr := conn . Refresh ( ) if refreshErr == nil && conn . AccessToken != " " { newResp , newErr := getClientForProxyURL ( conn . MetadataServiceProxy ) . Do ( req ) if newErr != nil { return nil , newErr } if newResp . StatusCode != 200 { defer newResp . Body . Close ( ) return nil , httperror . New ( newResp . Status , newResp . Body ) } return & newResp . Body , nil } } if resp . StatusCode != 200 { defer resp . Body . Close ( ) return nil , httperror . New ( resp . Status , resp . Body ) } return & resp . Body , nil }
MakeRequest Executes an HTTP request using a session token
MakeRequest Executes an HTTP request using a session token
// Attempt to seamlessly grab a new access token if our current token has expired