mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #30542 from skabashnyuk/master
Fixes work of inspectResponse in case of ContentLength=-1
This commit is contained in:
commit
04f0e616f2
2 changed files with 21 additions and 1 deletions
|
@ -129,7 +129,7 @@ func inspectResponse(ct string, r io.ReadCloser, clen int64) (string, io.ReadClo
|
||||||
return ct, r, err
|
return ct, r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
preambleR := bytes.NewReader(preamble)
|
preambleR := bytes.NewReader(preamble[:rlen])
|
||||||
bodyReader := ioutil.NopCloser(io.MultiReader(preambleR, r))
|
bodyReader := ioutil.NopCloser(io.MultiReader(preambleR, r))
|
||||||
// Some web servers will use application/octet-stream as the default
|
// Some web servers will use application/octet-stream as the default
|
||||||
// content type for files without an extension (e.g. 'Dockerfile')
|
// content type for files without an extension (e.g. 'Dockerfile')
|
||||||
|
|
|
@ -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) {
|
func TestMakeRemoteContext(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
|
contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
Loading…
Reference in a new issue