Remove httputils dependency from API client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-12-14 16:45:29 -05:00
parent ecc3717cb1
commit 83b5729f64
2 changed files with 30 additions and 5 deletions

View file

@ -5,14 +5,16 @@ import (
"encoding/json"
"net/http"
"net/url"
"regexp"
"strconv"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/httputils"
"github.com/docker/docker/pkg/units"
"github.com/docker/docker/runconfig"
)
var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`)
// 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
// close it.
@ -35,10 +37,7 @@ func (cli *Client) ImageBuild(options types.ImageBuildOptions) (types.ImageBuild
return types.ImageBuildResponse{}, err
}
var osType string
if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil {
osType = h.OS
}
osType := getDockerOS(serverResp.header.Get("Server"))
return types.ImageBuildResponse{
Body: serverResp.body,
@ -111,3 +110,12 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
return query, nil
}
func getDockerOS(serverHeader string) string {
var osType string
matches := headerRegexp.FindStringSubmatch(serverHeader)
if len(matches) > 0 {
osType = matches[1]
}
return osType
}

View file

@ -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)
}
}
}