fix mime bug which will make server not recognize filename without dot

newgen v1.0.0rc1
兔子 4 years ago
parent 9e7ad45f06
commit 382badb0cc

@ -55,8 +55,8 @@ func RunHttpServer(listenIp, port, auth, folderPath, certKey, version, indexFile
func (v VtqeHttpServer) httpListen(w http.ResponseWriter, r *http.Request) { func (v VtqeHttpServer) httpListen(w http.ResponseWriter, r *http.Request) {
log := starlog.Std.NewFlag() log := starlog.Std.NewFlag()
w.Header().Set("Server", "Vicorique") w.Header().Set("Server", "Victorique")
w.Header().Set("Powered By", "B612.ME") w.Header().Set("Powered", "B612.ME")
write401 := func() { write401 := func() {
w.Header().Set("WWW-Authenticate", ` Basic realm="Please Enter Passwd"`) w.Header().Set("WWW-Authenticate", ` Basic realm="Please Enter Passwd"`)
w.WriteHeader(401) w.WriteHeader(401)
@ -138,7 +138,7 @@ func (v VtqeHttpServer) httpListen(w http.ResponseWriter, r *http.Request) {
} }
fpinfo, _ := os.Stat(fullpath) fpinfo, _ := os.Stat(fullpath)
name := filepath.Base(fullpath) name := filepath.Base(fullpath)
ext := filepath.Ext(name)[1:] ext := filepath.Ext(name)
mime := GetMIME(ext) mime := GetMIME(ext)
if mime == "" || v.stopMime { if mime == "" || v.stopMime {
w.Header().Set("Content-Type", "application/download") w.Header().Set("Content-Type", "application/download")

@ -1,6 +1,10 @@
package httpserver package httpserver
func GetMIME(ext string) string { func GetMIME(ext string) string {
if len(ext) == 0 || ext == "." {
return ""
}
ext = ext[1:]
switch ext { switch ext {
case "123": case "123":
return "application/vnd.lotus-1-2-3" return "application/vnd.lotus-1-2-3"

Loading…
Cancel
Save