升级mime

This commit is contained in:
hoteas
2017-10-12 02:07:51 +00:00
parent 2ba3fa42cf
commit e8a27635fb
2 changed files with 566 additions and 11 deletions
+10 -11
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
@@ -207,14 +208,14 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
Resp: w, Req: req, Application: this, RouterString: s, Config: this.Config, Db: &this.Db, HandlerStr: req.RequestURI}
//header默认设置
header := w.Header()
header.Set("Content-Type", "text/html; charset=utf-8")
//访问拦截true继续false暂停
connectListenerLen := len(this.connectListener)
if connectListenerLen != 0 {
for i := 0; i < connectListenerLen; i++ {
if !this.connectListener[i](&context) {
header.Set("Content-Type", "text/html; charset=utf-8")
context.View()
return
}
@@ -228,7 +229,7 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
if this.Router[s[0]] != nil && this.Router[s[0]][s[1]] != nil && this.Router[s[0]][s[1]][s[2]] != nil {
//控制层
this.Router[s[0]][s[1]][s[2]](&context)
header.Set("Content-Type", "text/html; charset=utf-8")
//header.Set("Content-Type", "text/html; charset=utf-8")
context.View()
return
}
@@ -261,17 +262,15 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
return
}
//类型判断并设置Content-Type
if strings.Contains(path, ".css") {
header.Set("Content-Type", "text/css; charset=utf-8")
//header.Get(Config["sessionName"].(string))
}
//设置header
mimeStr := Substr(path, strings.LastIndex(path, "."), len(path))
//fmt.Println(mimeStr)
//类型判断并设置Content-Type
if strings.Contains(path, ".js") {
header.Set("Content-Type", "application/javascript; charset=utf-8")
//header.Get(Config["sessionName"].(string))
if value, ok := mimeMaps[mimeStr]; ok {
header.Set("Content-Type", value)
}
header.Set("Cache-Control", "public")
//w.Write(data)
http.ServeFile(w, req, path)