diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index a51ba5c34..bd16f1d59 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -426,9 +426,9 @@ func detectContentType(fileInfo os.FileInfo, path string) string { // We ignore errors because this is optional information if err == nil { fileBytes := make([]byte, 512) - _, err := f.Read(fileBytes) + n, err := f.Read(fileBytes) if err == nil { - contentType = http.DetectContentType(fileBytes) + contentType = http.DetectContentType(fileBytes[:n]) } f.Close() } diff --git a/client/allocdir/alloc_dir_test.go b/client/allocdir/alloc_dir_test.go index 82b3ae1cb..8dc61b5cd 100644 --- a/client/allocdir/alloc_dir_test.go +++ b/client/allocdir/alloc_dir_test.go @@ -493,6 +493,7 @@ func TestAllocDir_DetectContentType(t *testing.T) { "input/test.json": "application/json", "input/test.txt": "text/plain; charset=utf-8", "input/test.go": "text/plain; charset=utf-8", + "input/test.hcl": "text/plain; charset=utf-8", } for _, file := range testFiles { fileInfo, err := os.Stat(file) diff --git a/client/allocdir/input/test.hcl b/client/allocdir/input/test.hcl new file mode 100644 index 000000000..64aa42c4d --- /dev/null +++ b/client/allocdir/input/test.hcl @@ -0,0 +1,3 @@ +test "test" { + test = "test" +}