wrap fileHandler to RouterHandle
(fileHandler http.Handler, excludeExtension []string)
| 606 | |
| 607 | // wrap fileHandler to RouterHandle |
| 608 | func (r *router) wrapFileHandle(fileHandler http.Handler, excludeExtension []string) RouterHandle { |
| 609 | return func(httpCtx Context) { |
| 610 | httpCtx.setHandler(transferStaticFileHandler(fileHandler, excludeExtension)) |
| 611 | startTime := time.Now() |
| 612 | httpCtx.Request().realUrl = httpCtx.Request().URL.String() |
| 613 | httpCtx.Request().URL.Path = httpCtx.RouterParams().ByName("filepath") |
| 614 | if httpCtx.HttpServer().ServerConfig().EnabledStaticFileMiddleware && len(httpCtx.RouterNode().AppMiddlewares()) > 0 { |
| 615 | ctxErr := httpCtx.RouterNode().AppMiddlewares()[0].Handle(httpCtx) |
| 616 | if ctxErr != nil { |
| 617 | if r.server.DotApp.ExceptionHandler != nil { |
| 618 | r.server.DotApp.ExceptionHandler(httpCtx, ctxErr) |
| 619 | r.server.StateInfo().AddErrorCount(httpCtx.Request().Path(), ctxErr, 1) |
| 620 | } |
| 621 | } |
| 622 | } else { |
| 623 | httpCtx.Handler()(httpCtx) |
| 624 | } |
| 625 | if r.server.Logger().IsEnabledLog() { |
| 626 | timetaken := int64(time.Now().Sub(startTime) / time.Millisecond) |
| 627 | r.server.Logger().Debug(httpCtx.Request().Url()+" "+logRequest(httpCtx.Request().Request, timetaken), LogTarget_HttpRequest) |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | // wrap HttpHandle to websocket.Handle |
| 633 | func (r *router) wrapWebSocketHandle(handler HttpHandle) websocket.Handler { |
no test coverage detected