mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 03:30:53 +00:00
fix #2017
This commit is contained in:
parent
421bf97b84
commit
868e14b8ba
@ -40,12 +40,14 @@ var (
|
|||||||
// BeegoInput operates the http request header, data, cookie and body.
|
// BeegoInput operates the http request header, data, cookie and body.
|
||||||
// it also contains router params and current session.
|
// it also contains router params and current session.
|
||||||
type BeegoInput struct {
|
type BeegoInput struct {
|
||||||
Context *Context
|
Context *Context
|
||||||
CruSession session.Store
|
CruSession session.Store
|
||||||
pnames []string
|
pnames []string
|
||||||
pvalues []string
|
pvalues []string
|
||||||
data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
|
data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
|
||||||
RequestBody []byte
|
RequestBody []byte
|
||||||
|
RunMethod string
|
||||||
|
RunController reflect.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInput return BeegoInput generated by Context.
|
// NewInput return BeegoInput generated by Context.
|
||||||
|
17
router.go
17
router.go
@ -685,8 +685,16 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
if len(p.filters[BeforeRouter]) > 0 && p.execFilter(context, urlPath, BeforeRouter) {
|
if len(p.filters[BeforeRouter]) > 0 && p.execFilter(context, urlPath, BeforeRouter) {
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
|
// User can define RunController and RunMethod in filter
|
||||||
|
if context.Input.RunController != nil && context.Input.RunMethod != "" {
|
||||||
|
findRouter = true
|
||||||
|
isRunnable = true
|
||||||
|
runMethod = context.Input.RunMethod
|
||||||
|
runRouter = context.Input.RunController
|
||||||
|
} else {
|
||||||
|
routerInfo, findRouter = p.FindRouter(context)
|
||||||
|
}
|
||||||
|
|
||||||
routerInfo, findRouter = p.FindRouter(context)
|
|
||||||
//if no matches to url, throw a not found exception
|
//if no matches to url, throw a not found exception
|
||||||
if !findRouter {
|
if !findRouter {
|
||||||
exception("404", context)
|
exception("404", context)
|
||||||
@ -698,15 +706,16 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//store router pattern into context
|
|
||||||
context.Input.SetData("RouterPattern", routerInfo.pattern)
|
|
||||||
|
|
||||||
//execute middleware filters
|
//execute middleware filters
|
||||||
if len(p.filters[BeforeExec]) > 0 && p.execFilter(context, urlPath, BeforeExec) {
|
if len(p.filters[BeforeExec]) > 0 && p.execFilter(context, urlPath, BeforeExec) {
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
|
|
||||||
if routerInfo != nil {
|
if routerInfo != nil {
|
||||||
|
if BConfig.RunMode == DEV {
|
||||||
|
//store router pattern into context
|
||||||
|
context.Input.SetData("RouterPattern", routerInfo.pattern)
|
||||||
|
}
|
||||||
if routerInfo.routerType == routerTypeRESTFul {
|
if routerInfo.routerType == routerTypeRESTFul {
|
||||||
if _, ok := routerInfo.methods[r.Method]; ok {
|
if _, ok := routerInfo.methods[r.Method]; ok {
|
||||||
isRunnable = true
|
isRunnable = true
|
||||||
|
Loading…
Reference in New Issue
Block a user