mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:57:07 +08:00
Merge 6e2957df824d25d14aad9f9890bac448c632d539 into 97729696c0c30725e8d239ad03814eb8c80ce8f1
This commit is contained in:
commit
1df03a719d
16
gin.go
16
gin.go
@ -5,8 +5,11 @@ import (
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"html/template"
|
||||
"math"
|
||||
"mime"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -221,6 +224,19 @@ func (group *RouterGroup) Static(p, root string) {
|
||||
group.HEAD(p, func(c *Context) {
|
||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||
})
|
||||
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user