4f8750d4 by 张磊

1

1 parent a89f14d8
......@@ -18,6 +18,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
......@@ -68,17 +69,26 @@ func serverStaticRouter(ctx *context.Context) {
if !DirectoryIndex {
exception("403", ctx)
return
} else if ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path)-1] != '/' {
http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path+"/", 302)
} else if ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path) - 1] != '/' {
http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path + "/", 302)
return
}
} else if strings.HasSuffix(requestPath, "/index.html") {
file := path.Join(staticDir, requestPath)
if utils.FileExists(file) {
http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
//file := path.Join(staticDir, requestPath)
//if utils.FileExists(file) {
//http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
//return
//}
//http.ServeFile can not use index.html
dirName, fileName := filepath.Split(file)
fs := http.Dir(dirName)
f, _ := fs.Open(fileName)
defer f.Close()
d, _ := f.Stat()
http.ServeContent(ctx.ResponseWriter, ctx.Request, d.Name(), d.ModTime(), f)
return
}
}
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
isStaticFileToCompress := false
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!