diff options
author | Bwko <bouwko@gmail.com> | 2017-01-25 05:26:31 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-01-25 12:26:31 +0800 |
commit | 8555e888d8690df718b1673b8409a29d05770cf4 (patch) | |
tree | 19b7cb9e6f548b87aef122b66f99e04dcfe36335 /vendor/gopkg.in | |
parent | 8093b3372e812af6a5c3aab32559881011861243 (diff) | |
download | gitea-8555e888d8690df718b1673b8409a29d05770cf4.tar.gz gitea-8555e888d8690df718b1673b8409a29d05770cf4.zip |
Add ETag header to avatars (#721)
Diffstat (limited to 'vendor/gopkg.in')
-rw-r--r-- | vendor/gopkg.in/macaron.v1/macaron.go | 2 | ||||
-rw-r--r-- | vendor/gopkg.in/macaron.v1/render.go | 11 | ||||
-rw-r--r-- | vendor/gopkg.in/macaron.v1/router.go | 4 | ||||
-rw-r--r-- | vendor/gopkg.in/macaron.v1/static.go | 15 |
4 files changed, 30 insertions, 2 deletions
diff --git a/vendor/gopkg.in/macaron.v1/macaron.go b/vendor/gopkg.in/macaron.v1/macaron.go index 442402ead7..9ff5668ad0 100644 --- a/vendor/gopkg.in/macaron.v1/macaron.go +++ b/vendor/gopkg.in/macaron.v1/macaron.go @@ -32,7 +32,7 @@ import ( "github.com/go-macaron/inject" ) -const _VERSION = "1.1.8.0826" +const _VERSION = "1.1.12.0122" func Version() string { return _VERSION diff --git a/vendor/gopkg.in/macaron.v1/render.go b/vendor/gopkg.in/macaron.v1/render.go index ff2dcaacdd..f45e431240 100644 --- a/vendor/gopkg.in/macaron.v1/render.go +++ b/vendor/gopkg.in/macaron.v1/render.go @@ -21,6 +21,7 @@ import ( "encoding/xml" "fmt" "html/template" + "io" "io/ioutil" "net/http" "os" @@ -72,6 +73,7 @@ type ( // TemplateFileSystem represents a interface of template file system that able to list all files. TemplateFileSystem interface { ListFiles() []TemplateFile + Get(string) (io.Reader, error) } // Delims represents a set of Left and Right delimiters for HTML template rendering @@ -246,6 +248,15 @@ func (fs TplFileSystem) ListFiles() []TemplateFile { return fs.files } +func (fs TplFileSystem) Get(name string) (io.Reader, error) { + for i := range fs.files { + if fs.files[i].Name()+fs.files[i].Ext() == name { + return bytes.NewReader(fs.files[i].Data()), nil + } + } + return nil, fmt.Errorf("file '%s' not found", name) +} + func PrepareCharset(charset string) string { if len(charset) != 0 { return "; charset=" + charset diff --git a/vendor/gopkg.in/macaron.v1/router.go b/vendor/gopkg.in/macaron.v1/router.go index f9b421a330..befa55f476 100644 --- a/vendor/gopkg.in/macaron.v1/router.go +++ b/vendor/gopkg.in/macaron.v1/router.go @@ -258,7 +258,9 @@ func (r *Router) NotFound(handlers ...Handler) { validateHandlers(handlers) r.notFound = func(rw http.ResponseWriter, req *http.Request) { c := r.m.createContext(rw, req) - c.handlers = append(r.m.handlers, handlers...) + c.handlers = make([]Handler, 0, len(r.m.handlers)+len(handlers)) + c.handlers = append(c.handlers, r.m.handlers...) + c.handlers = append(c.handlers, handlers...) c.run() } } diff --git a/vendor/gopkg.in/macaron.v1/static.go b/vendor/gopkg.in/macaron.v1/static.go index 4ff8342fc5..60c521110e 100644 --- a/vendor/gopkg.in/macaron.v1/static.go +++ b/vendor/gopkg.in/macaron.v1/static.go @@ -16,6 +16,7 @@ package macaron import ( + "encoding/base64" "log" "net/http" "path" @@ -35,6 +36,9 @@ type StaticOptions struct { // Expires defines which user-defined function to use for producing a HTTP Expires Header // https://developers.google.com/speed/docs/insights/LeverageBrowserCaching Expires func() string + // ETag defines if we should add an ETag header + // https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#validating-cached-responses-with-etags + ETag bool // FileSystem is the interface for supporting any implmentation of file system. FileSystem http.FileSystem } @@ -172,10 +176,21 @@ func staticHandler(ctx *Context, log *log.Logger, opt StaticOptions) bool { ctx.Resp.Header().Set("Expires", opt.Expires()) } + if opt.ETag { + tag := GenerateETag(string(fi.Size()), fi.Name(), fi.ModTime().UTC().Format(http.TimeFormat)) + ctx.Resp.Header().Set("ETag", tag) + } + http.ServeContent(ctx.Resp, ctx.Req.Request, file, fi.ModTime(), f) return true } +// GenerateETag generates an ETag based on size, filename and file modification time +func GenerateETag(fileSize, fileName, modTime string) string { + etag := fileSize + fileName + modTime + return base64.StdEncoding.EncodeToString([]byte(etag)) +} + // Static returns a middleware handler that serves static files in the given directory. func Static(directory string, staticOpt ...StaticOptions) Handler { opt := prepareStaticOptions(directory, staticOpt) |