1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-29 22:48:07 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-03-12 05:14:15 -08:00
parent 7263e50e10
commit 082814c776
9 changed files with 129 additions and 40 deletions

View File

@@ -2,11 +2,8 @@ package middleware
import (
"fmt"
"io"
"mime"
"net/http"
"path"
"path/filepath"
"github.com/labstack/echo"
)
@@ -19,10 +16,10 @@ type (
}
)
func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
func Static(root string, options ...StaticOptions) echo.MiddlewareFunc {
return func(next echo.Handler) echo.Handler {
// Default options
opts := new(StaticOptions)
opts := StaticOptions{}
if len(options) > 0 {
opts = options[0]
}
@@ -85,23 +82,7 @@ func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
}
fi, _ = f.Stat() // Index file stat
}
ct := mime.TypeByExtension(filepath.Ext(fi.Name()))
if ct == "" {
ct = echo.OctetStream
}
c.Response().Header().Set(echo.ContentType, ct)
c.Response().WriteHeader(http.StatusOK)
_, err = io.Copy(c.Response(), f)
return err
// TODO:
// http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
return echo.ServeContent(c.Request(), c.Response(), f, fi)
})
}
}
// Favicon serves the default favicon - GET /favicon.ico.
func Favicon() echo.HandlerFunc {
return func(c echo.Context) error {
return nil
}
}