474a16a7 by astaxie

beego: improve the static file server

1 parent 1d36b19c
...@@ -383,10 +383,6 @@ func initBeforeHttpRun() { ...@@ -383,10 +383,6 @@ func initBeforeHttpRun() {
383 middleware.AppName = AppName 383 middleware.AppName = AppName
384 middleware.RegisterErrorHandler() 384 middleware.RegisterErrorHandler()
385 385
386 for u, _ := range StaticDir {
387 Get(u, serverStaticRouter)
388 Get(u+"/*", serverStaticRouter)
389 }
390 if EnableDocs { 386 if EnableDocs {
391 Get("/docs", serverDocs) 387 Get("/docs", serverDocs)
392 Get("/docs/*", serverDocs) 388 Get("/docs/*", serverDocs)
......
...@@ -32,7 +32,8 @@ import ( ...@@ -32,7 +32,8 @@ import (
32 32
33 const ( 33 const (
34 // default filter execution points 34 // default filter execution points
35 BeforeRouter = iota 35 BeforeStatic = iota
36 BeforeRouter
36 BeforeExec 37 BeforeExec
37 AfterExec 38 AfterExec
38 FinishRouter 39 FinishRouter
...@@ -577,6 +578,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -577,6 +578,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
577 return false 578 return false
578 } 579 }
579 580
581 if do_filter(BeforeStatic) {
582 goto Admin
583 }
584
585 serverStaticRouter(context)
586 if w.started {
587 goto Admin
588 }
589
580 // session init 590 // session init
581 if SessionOn { 591 if SessionOn {
582 context.Input.CruSession = GlobalSessions.SessionStart(w, r) 592 context.Input.CruSession = GlobalSessions.SessionStart(w, r)
......
...@@ -22,6 +22,9 @@ import ( ...@@ -22,6 +22,9 @@ import (
22 ) 22 )
23 23
24 func serverStaticRouter(ctx *context.Context) { 24 func serverStaticRouter(ctx *context.Context) {
25 if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" {
26 return
27 }
25 requestPath := path.Clean(ctx.Input.Request.URL.Path) 28 requestPath := path.Clean(ctx.Input.Request.URL.Path)
26 for prefix, staticDir := range StaticDir { 29 for prefix, staticDir := range StaticDir {
27 if len(prefix) == 0 { 30 if len(prefix) == 0 {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!