diff --git a/gin.go b/gin.go index 106e1b9c..71ec29b0 100644 --- a/gin.go +++ b/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 {