1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fixed response header and get handler name

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-02-17 11:58:03 -08:00
parent d14b8f5ba4
commit e91717552f
3 changed files with 20 additions and 8 deletions

View File

@ -474,5 +474,9 @@ func (binder) Bind(r engine.Request, i interface{}) (err error) {
}
func handlerName(h Handler) string {
t := reflect.ValueOf(h).Type()
if t.Kind() == reflect.Func {
return runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
}
return t.String()
}

View File

@ -96,7 +96,8 @@ func (s *Server) Start() {
// Response
res := s.pool.response.Get().(*Response)
resHdr := s.pool.header.Get().(*Header)
res.reset(w, reqHdr)
resHdr.reset(w.Header())
res.reset(w, resHdr)
s.handler(req, res)

View File

@ -12,11 +12,18 @@ import (
type (
Static struct {
Root string
Browse bool
Index string
Browse bool
}
)
func NewStatic(root string) *Static {
return &Static{
Root: root,
Index: "index.html",
}
}
func (s Static) Handle(c echo.Context) error {
fs := http.Dir(s.Root)
file := c.P(0)
@ -49,9 +56,9 @@ func (s Static) Handle(c echo.Context) error {
}
// Create a directory index
w := c.Response()
w.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8)
if _, err = fmt.Fprintf(w, "<pre>\n"); err != nil {
res := c.Response()
res.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8)
if _, err = fmt.Fprintf(res, "<pre>\n"); err != nil {
return err
}
for _, d := range dirs {
@ -61,11 +68,11 @@ func (s Static) Handle(c echo.Context) error {
color = "#e91e63"
name += "/"
}
if _, err = fmt.Fprintf(w, "<a href=\"%s\" style=\"color: %s;\">%s</a>\n", name, color, name); err != nil {
if _, err = fmt.Fprintf(res, "<a href=\"%s\" style=\"color: %s;\">%s</a>\n", name, color, name); err != nil {
return err
}
}
_, err = fmt.Fprintf(w, "</pre>\n")
_, err = fmt.Fprintf(res, "</pre>\n")
return err
}
return echo.ErrNotFound