(refs #105)Specify suitable Content-Type header for downloaded file.

This commit is contained in:
takezoe
2013-09-29 16:26:20 +09:00
parent 54bc8c16d8
commit 5430564065
2 changed files with 15 additions and 2 deletions

View File

@@ -93,8 +93,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
if(raw){
// Download
contentType = "application/octet-stream"
JGitUtil.getContent(git, objectId, false).get
val mimeType = FileUtil.getMimeType(path)
val bytes = JGitUtil.getContent(git, objectId, false).get
contentType = if(mimeType == "application/octet-stream" && FileUtil.isText(bytes)){
"text/plain"
} else {
mimeType
}
//response.setHeader("Content-Disposition", s"inline; filename=${FileUtil.getFileName(path)}")
bytes
} else {
// Viewer
val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize)