mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:00:55 +00:00
remove contextBuffer fix #396
This commit is contained in:
parent
2ad399db05
commit
419c3fc772
51
router.go
51
router.go
@ -40,21 +40,19 @@ type controllerInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ControllerRegistor struct {
|
type ControllerRegistor struct {
|
||||||
routers []*controllerInfo // regexp router storage
|
routers []*controllerInfo // regexp router storage
|
||||||
fixrouters []*controllerInfo // fixed router storage
|
fixrouters []*controllerInfo // fixed router storage
|
||||||
enableFilter bool
|
enableFilter bool
|
||||||
filters map[int][]*FilterRouter
|
filters map[int][]*FilterRouter
|
||||||
enableAuto bool
|
enableAuto bool
|
||||||
autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type
|
autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type
|
||||||
contextBuffer chan *beecontext.Context //context buffer pool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewControllerRegistor() *ControllerRegistor {
|
func NewControllerRegistor() *ControllerRegistor {
|
||||||
return &ControllerRegistor{
|
return &ControllerRegistor{
|
||||||
routers: make([]*controllerInfo, 0),
|
routers: make([]*controllerInfo, 0),
|
||||||
autoRouter: make(map[string]map[string]reflect.Type),
|
autoRouter: make(map[string]map[string]reflect.Type),
|
||||||
filters: make(map[int][]*FilterRouter),
|
filters: make(map[int][]*FilterRouter),
|
||||||
contextBuffer: make(chan *beecontext.Context, 1000),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,31 +438,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
w.Header().Set("Server", BeegoServerName)
|
w.Header().Set("Server", BeegoServerName)
|
||||||
|
|
||||||
// init context
|
// init context
|
||||||
var context *beecontext.Context
|
context := &beecontext.Context{
|
||||||
select {
|
ResponseWriter: w,
|
||||||
case context = <-p.contextBuffer:
|
Request: r,
|
||||||
context.ResponseWriter = w
|
Input: beecontext.NewInput(r),
|
||||||
context.Request = r
|
Output: beecontext.NewOutput(),
|
||||||
context.Input.Request = r
|
|
||||||
default:
|
|
||||||
context = &beecontext.Context{
|
|
||||||
ResponseWriter: w,
|
|
||||||
Request: r,
|
|
||||||
Input: beecontext.NewInput(r),
|
|
||||||
Output: beecontext.NewOutput(),
|
|
||||||
}
|
|
||||||
context.Output.Context = context
|
|
||||||
context.Output.EnableGzip = EnableGzip
|
|
||||||
}
|
}
|
||||||
|
context.Output.Context = context
|
||||||
defer func() {
|
context.Output.EnableGzip = EnableGzip
|
||||||
if context != nil {
|
|
||||||
select {
|
|
||||||
case p.contextBuffer <- context:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if context.Input.IsWebsocket() {
|
if context.Input.IsWebsocket() {
|
||||||
context.ResponseWriter = rw
|
context.ResponseWriter = rw
|
||||||
|
Loading…
Reference in New Issue
Block a user