MCPcopy Create free account
hub / github.com/devfeel/dotweb / wrapFileHandle

Method wrapFileHandle

router.go:608–630  ·  view source on GitHub ↗

wrap fileHandler to RouterHandle

(fileHandler http.Handler, excludeExtension []string)

Source from the content-addressed store, hash-verified

606
607// wrap fileHandler to RouterHandle
608func (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
633func (r *router) wrapWebSocketHandle(handler HttpHandle) websocket.Handler {

Callers 1

RegisterServerFileMethod · 0.95

Calls 15

logRequestFunction · 0.85
StringMethod · 0.80
ByNameMethod · 0.80
ServerConfigMethod · 0.80
AddErrorCountMethod · 0.80
UrlMethod · 0.80
setHandlerMethod · 0.65
RequestMethod · 0.65
RouterParamsMethod · 0.65
HttpServerMethod · 0.65
AppMiddlewaresMethod · 0.65

Tested by

no test coverage detected