mirror of https://github.com/docker/docs.git
Merge pull request #18650 from calavera/remove_httputils_dep_from_api
Remove httputils dependency from API client lib.
This commit is contained in:
commit
2ec34dca05
|
|
@ -5,14 +5,16 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/httputils"
|
|
||||||
"github.com/docker/docker/pkg/units"
|
"github.com/docker/docker/pkg/units"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`)
|
||||||
|
|
||||||
// ImageBuild sends request to the daemon to build images.
|
// ImageBuild sends request to the daemon to build images.
|
||||||
// The Body in the response implement an io.ReadCloser and it's up to the caller to
|
// The Body in the response implement an io.ReadCloser and it's up to the caller to
|
||||||
// close it.
|
// close it.
|
||||||
|
|
@ -35,10 +37,7 @@ func (cli *Client) ImageBuild(options types.ImageBuildOptions) (types.ImageBuild
|
||||||
return types.ImageBuildResponse{}, err
|
return types.ImageBuildResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var osType string
|
osType := getDockerOS(serverResp.header.Get("Server"))
|
||||||
if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
|
|
||||||
osType = h.OS
|
|
||||||
}
|
|
||||||
|
|
||||||
return types.ImageBuildResponse{
|
return types.ImageBuildResponse{
|
||||||
Body: serverResp.body,
|
Body: serverResp.body,
|
||||||
|
|
@ -111,3 +110,12 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
|
||||||
|
|
||||||
return query, nil
|
return query, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDockerOS(serverHeader string) string {
|
||||||
|
var osType string
|
||||||
|
matches := headerRegexp.FindStringSubmatch(serverHeader)
|
||||||
|
if len(matches) > 0 {
|
||||||
|
osType = matches[1]
|
||||||
|
}
|
||||||
|
return osType
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestGetDockerOS(t *testing.T) {
|
||||||
|
cases := map[string]string{
|
||||||
|
"Docker/v1.22 (linux)": "linux",
|
||||||
|
"Docker/v1.22 (windows)": "windows",
|
||||||
|
"Foo/v1.22 (bar)": "",
|
||||||
|
}
|
||||||
|
for header, os := range cases {
|
||||||
|
g := getDockerOS(header)
|
||||||
|
if g != os {
|
||||||
|
t.Fatalf("Expected %s, got %s", os, g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue