mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 11:10:57 +00:00
beego: improve the static file server
This commit is contained in:
parent
1d36b19cab
commit
474a16a7a0
4
beego.go
4
beego.go
@ -383,10 +383,6 @@ func initBeforeHttpRun() {
|
|||||||
middleware.AppName = AppName
|
middleware.AppName = AppName
|
||||||
middleware.RegisterErrorHandler()
|
middleware.RegisterErrorHandler()
|
||||||
|
|
||||||
for u, _ := range StaticDir {
|
|
||||||
Get(u, serverStaticRouter)
|
|
||||||
Get(u+"/*", serverStaticRouter)
|
|
||||||
}
|
|
||||||
if EnableDocs {
|
if EnableDocs {
|
||||||
Get("/docs", serverDocs)
|
Get("/docs", serverDocs)
|
||||||
Get("/docs/*", serverDocs)
|
Get("/docs/*", serverDocs)
|
||||||
|
12
router.go
12
router.go
@ -32,7 +32,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// default filter execution points
|
// default filter execution points
|
||||||
BeforeRouter = iota
|
BeforeStatic = iota
|
||||||
|
BeforeRouter
|
||||||
BeforeExec
|
BeforeExec
|
||||||
AfterExec
|
AfterExec
|
||||||
FinishRouter
|
FinishRouter
|
||||||
@ -577,6 +578,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if do_filter(BeforeStatic) {
|
||||||
|
goto Admin
|
||||||
|
}
|
||||||
|
|
||||||
|
serverStaticRouter(context)
|
||||||
|
if w.started {
|
||||||
|
goto Admin
|
||||||
|
}
|
||||||
|
|
||||||
// session init
|
// session init
|
||||||
if SessionOn {
|
if SessionOn {
|
||||||
context.Input.CruSession = GlobalSessions.SessionStart(w, r)
|
context.Input.CruSession = GlobalSessions.SessionStart(w, r)
|
||||||
|
@ -22,6 +22,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func serverStaticRouter(ctx *context.Context) {
|
func serverStaticRouter(ctx *context.Context) {
|
||||||
|
if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" {
|
||||||
|
return
|
||||||
|
}
|
||||||
requestPath := path.Clean(ctx.Input.Request.URL.Path)
|
requestPath := path.Clean(ctx.Input.Request.URL.Path)
|
||||||
for prefix, staticDir := range StaticDir {
|
for prefix, staticDir := range StaticDir {
|
||||||
if len(prefix) == 0 {
|
if len(prefix) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user