diff --git a/echo.go b/echo.go index 645043ff..ec7815ab 100644 --- a/echo.go +++ b/echo.go @@ -142,6 +142,7 @@ const ( WWWAuthenticate = "WWW-Authenticate" XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-IP" + //----------- // Protocols //----------- @@ -207,12 +208,12 @@ func New() (e *Echo) { return } -func (f MiddlewareFunc) Handle(h Handler) Handler { - return f(h) +func (m MiddlewareFunc) Handle(h Handler) Handler { + return m(h) } -func (f HandlerFunc) Handle(c Context) error { - return f(c) +func (h HandlerFunc) Handle(c Context) error { + return h(c) } // Router returns router. diff --git a/engine/standard/server.go b/engine/standard/server.go index ea16de51..7a8b9180 100644 --- a/engine/standard/server.go +++ b/engine/standard/server.go @@ -67,7 +67,7 @@ func NewConfig(c *engine.Config) (s *Server) { }, }, handler: func(req engine.Request, res engine.Response) { - s.logger.Warn("handler not set") + s.logger.Fatal("handler not set") }, logger: log.New("echo"), } @@ -84,30 +84,7 @@ func (s *Server) SetLogger(l logger.Logger) { func (s *Server) Start() { s.Addr = s.config.Address - s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // Request - req := s.pool.request.Get().(*Request) - reqHdr := s.pool.header.Get().(*Header) - reqURL := s.pool.url.Get().(*URL) - reqHdr.reset(r.Header) - reqURL.reset(r.URL) - req.reset(r, reqHdr, reqURL) - - // Response - res := s.pool.response.Get().(*Response) - resHdr := s.pool.header.Get().(*Header) - resHdr.reset(w.Header()) - res.reset(w, resHdr) - - s.handler(req, res) - - s.pool.request.Put(req) - s.pool.header.Put(reqHdr) - s.pool.url.Put(reqURL) - s.pool.response.Put(res) - s.pool.header.Put(resHdr) - }) - + s.Handler = s certfile := s.config.TLSCertfile keyfile := s.config.TLSKeyfile if certfile != "" && keyfile != "" { @@ -116,3 +93,27 @@ func (s *Server) Start() { s.logger.Fatal(s.ListenAndServe()) } } + +func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // Request + req := s.pool.request.Get().(*Request) + reqHdr := s.pool.header.Get().(*Header) + reqURL := s.pool.url.Get().(*URL) + reqHdr.reset(r.Header) + reqURL.reset(r.URL) + req.reset(r, reqHdr, reqURL) + + // Response + res := s.pool.response.Get().(*Response) + resHdr := s.pool.header.Get().(*Header) + resHdr.reset(w.Header()) + res.reset(w, resHdr) + + s.handler(req, res) + + s.pool.request.Put(req) + s.pool.header.Put(reqHdr) + s.pool.url.Put(reqURL) + s.pool.response.Put(res) + s.pool.header.Put(resHdr) +}