summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-11-02 19:17:04 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-11-02 19:17:04 -0400
commitb51a2c03985f09845e498ece625f5e8a309b6086 (patch)
treeb592f25121cedb3ebaa83dea6cf2f953fceb4372
parent59294e30d099c6bddfa290278a8c0988a351606f (diff)
better MIME type detection
-rw-r--r--src/edit/util.go11
-rw-r--r--src/edit/views.go4
2 files changed, 12 insertions, 3 deletions
diff --git a/src/edit/util.go b/src/edit/util.go
index 566796c..b6dfde1 100644
--- a/src/edit/util.go
+++ b/src/edit/util.go
@@ -1,7 +1,10 @@
package main
import (
+ "mime"
+ "net/http"
"os/exec"
+ "path"
)
type exitError exec.ExitError
@@ -23,3 +26,11 @@ func errcheck(err error) {
panic(err)
}
}
+
+func getctype(name string, content []byte) string {
+ ctype := mime.TypeByExtension(path.Ext(name))
+ if ctype == "" {
+ ctype = http.DetectContentType(content)
+ }
+ return ctype
+}
diff --git a/src/edit/views.go b/src/edit/views.go
index 81a6945..f9ff618 100644
--- a/src/edit/views.go
+++ b/src/edit/views.go
@@ -3,8 +3,6 @@ package main
import (
"bytes"
"io"
- "mime"
- "path"
"strings"
"util"
)
@@ -62,7 +60,7 @@ func renderViewBlob(w io.Writer, upath string, file GitFile) error {
var buf bytes.Buffer
err = tmplViewBlob.Execute(&buf, map[string]string{
"path": upath,
- "ctype": mime.TypeByExtension(path.Ext(upath)),
+ "ctype": getctype(upath, content),
"content": string(content),
})
if err != nil {