From 22a9ec009b24f567e1feaeb32da25d6b2792c92a Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Sun, 29 Jan 2017 15:01:53 +0200 Subject: [PATCH 1/2] Fixes work of inspectResponse in case of ContentLength=-1 Signed-off-by: Sergii Kabashniuk --- builder/remote.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/remote.go b/builder/remote.go index f3a4329d16..b790301619 100644 --- a/builder/remote.go +++ b/builder/remote.go @@ -129,7 +129,7 @@ func inspectResponse(ct string, r io.ReadCloser, clen int64) (string, io.ReadClo return ct, r, err } - preambleR := bytes.NewReader(preamble) + preambleR := bytes.NewReader(preamble[:rlen]) bodyReader := ioutil.NopCloser(io.MultiReader(preambleR, r)) // Some web servers will use application/octet-stream as the default // content type for files without an extension (e.g. 'Dockerfile') From 28d59e57ca0c718fe5d7531626be1fe3b9b6564a Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Mon, 30 Jan 2017 10:02:47 +0200 Subject: [PATCH 2/2] Added test for the case if ContentLength = -1 Signed-off-by: Sergii Kabashniuk --- builder/remote_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builder/remote_test.go b/builder/remote_test.go index 691a084761..588eb85015 100644 --- a/builder/remote_test.go +++ b/builder/remote_test.go @@ -151,6 +151,26 @@ func TestInspectResponseEmptyContentType(t *testing.T) { } } +func TestUnknownContentLength(t *testing.T) { + content := []byte(dockerfileContents) + ct := "text/plain" + br := ioutil.NopCloser(bytes.NewReader(content)) + contentType, bReader, err := inspectResponse(ct, br, -1) + if err != nil { + t.Fatal(err) + } + if contentType != "text/plain" { + t.Fatalf("Content type should be 'text/plain' but is %q", contentType) + } + body, err := ioutil.ReadAll(bReader) + if err != nil { + t.Fatal(err) + } + if string(body) != dockerfileContents { + t.Fatalf("Corrupted response body %s", body) + } +} + func TestMakeRemoteContext(t *testing.T) { contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") defer cleanup()