Commit 6dc99b52 authored by Chao Xu's avatar Chao Xu

use http.client in ServerAPIVersions

parent 6a4c477a
...@@ -191,12 +191,29 @@ func extractGroupVersions(l *api.APIGroupList) []string { ...@@ -191,12 +191,29 @@ func extractGroupVersions(l *api.APIGroupList) []string {
// on the Version, Codec, and Prefix of the config, because it uses AbsPath and // on the Version, Codec, and Prefix of the config, because it uses AbsPath and
// takes the raw response. // takes the raw response.
func ServerAPIVersions(c *Config) (groupVersions []string, err error) { func ServerAPIVersions(c *Config) (groupVersions []string, err error) {
client, err := RESTClientFor(c) transport, err := TransportFor(c)
if err != nil {
return nil, err
}
client := http.Client{Transport: transport}
configCopy := *c
configCopy.Version = ""
configCopy.Prefix = ""
baseURL, err := defaultServerUrlFor(c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Get the groupVersions exposed at /api // Get the groupVersions exposed at /api
body, err := client.Get().AbsPath("api").Do().Raw() req, err := http.NewRequest("GET", baseURL.String()+"/api", nil)
if err != nil {
return nil, err
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -207,7 +224,15 @@ func ServerAPIVersions(c *Config) (groupVersions []string, err error) { ...@@ -207,7 +224,15 @@ func ServerAPIVersions(c *Config) (groupVersions []string, err error) {
} }
groupVersions = append(groupVersions, v.Versions...) groupVersions = append(groupVersions, v.Versions...)
// Get the groupVersions exposed at /apis // Get the groupVersions exposed at /apis
body, err = client.Get().AbsPath("apis").Do().Raw() req, err = http.NewRequest("GET", baseURL.String()+"/apis", nil)
if err != nil {
return nil, err
}
resp, err = client.Do(req)
if err != nil {
return nil, err
}
body, err = ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -519,9 +544,6 @@ func DefaultServerURL(host, prefix, version string, defaultTLS bool) (*url.URL, ...@@ -519,9 +544,6 @@ func DefaultServerURL(host, prefix, version string, defaultTLS bool) (*url.URL,
if host == "" { if host == "" {
return nil, fmt.Errorf("host must be a URL or a host:port pair") return nil, fmt.Errorf("host must be a URL or a host:port pair")
} }
if version == "" {
return nil, fmt.Errorf("version must be set")
}
base := host base := host
hostURL, err := url.Parse(base) hostURL, err := url.Parse(base)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment