mirror of
https://github.com/labstack/echo.git
synced 2025-04-25 12:24:55 +02:00
Content type for static middleware
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
5ada9b5f1b
commit
12e2c74eda
@ -3,8 +3,10 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
@ -83,9 +85,14 @@ func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
|
|||||||
}
|
}
|
||||||
fi, _ = f.Stat() // Index file stat
|
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)
|
c.Response().WriteHeader(http.StatusOK)
|
||||||
io.Copy(c.Response(), f)
|
_, err = io.Copy(c.Response(), f)
|
||||||
return nil
|
return err
|
||||||
// TODO:
|
// TODO:
|
||||||
// http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
|
// http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user