mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:57:07 +08:00
Added HEAD to RouterGroup.Static
This commit is contained in:
parent
3cf2d1338f
commit
6e2957df82
16
gin.go
16
gin.go
@ -11,8 +11,11 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -309,6 +312,19 @@ func (group *RouterGroup) Static(p, root string) {
|
|||||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||||
c.Request.URL.Path = original
|
c.Request.URL.Path = original
|
||||||
})
|
})
|
||||||
|
|
||||||
|
group.HEAD(p, func(c *Context) {
|
||||||
|
fp := path.Join(root, c.Params.ByName("filepath"))
|
||||||
|
|
||||||
|
info, err := os.Stat(fp)
|
||||||
|
if err != nil || info == nil {
|
||||||
|
c.Abort(404)
|
||||||
|
} else {
|
||||||
|
c.Writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fp)))
|
||||||
|
c.Writer.Header().Set("Last-Modified", info.ModTime().Format(http.TimeFormat))
|
||||||
|
c.Abort(200)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (group *RouterGroup) combineHandlers(handlers []HandlerFunc) []HandlerFunc {
|
func (group *RouterGroup) combineHandlers(handlers []HandlerFunc) []HandlerFunc {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user