Compare commits

..

No commits in common. "main" and "v0.1.5" have entirely different histories.
main ... v0.1.5

1 changed files with 7 additions and 12 deletions

View File

@ -130,11 +130,11 @@ func (s *Server) shouldCompress(req *http.Request) bool {
return false
}
func (s *Server) staticHandle(ctx *gin.Context, fp http.File) bool {
func (s *Server) staticHandle(ctx *gin.Context, fp http.File) {
uri := path.Clean(ctx.Request.URL.Path)
fi, err := fp.Stat()
if err != nil {
return false
return
}
if !fi.IsDir() {
//https://github.com/gin-contrib/gzip
@ -162,24 +162,19 @@ func (s *Server) staticHandle(ctx *gin.Context, fp http.File) bool {
}
http.ServeContent(ctx.Writer, ctx.Request, path.Base(uri), s.fs.modtime, fp)
ctx.Abort()
return true
}
func (s *Server) notFoundHandle(ctx *gin.Context) {
if s.fs != nil && ctx.Request.Method == http.MethodGet {
uri := path.Clean(ctx.Request.URL.Path)
if fp, err := s.fs.Open(uri); err == nil {
defer fp.Close()
if s.staticHandle(ctx, fp) {
return
}
s.staticHandle(ctx, fp)
fp.Close()
} else {
//if found compress file
//如果找到对应的压缩文件, 返回压缩文件
if fp, err := s.fs.Open(uri + ".gz"); err == nil {
defer fp.Close()
if s.staticHandle(ctx, fp) {
return
}
s.staticHandle(ctx, fp)
fp.Close()
}
}
}