| Index: appengine/gaemiddleware/context.go
|
| diff --git a/appengine/gaemiddleware/context.go b/appengine/gaemiddleware/context.go
|
| index 60a8bce83791c2a309cd777a9bd2c7ade7e19373..beffeacf1b1d2115fc0c5fb2a6ab13232005e4e2 100644
|
| --- a/appengine/gaemiddleware/context.go
|
| +++ b/appengine/gaemiddleware/context.go
|
| @@ -1,37 +1,36 @@
|
| // Copyright 2015 The LUCI Authors. All rights reserved.
|
| // Use of this source code is governed under the Apache License, Version 2.0
|
| // that can be found in the LICENSE file.
|
|
|
| package gaemiddleware
|
|
|
| import (
|
| "net/http"
|
|
|
| - "google.golang.org/appengine"
|
| -
|
| - "github.com/julienschmidt/httprouter"
|
| "golang.org/x/net/context"
|
| + "google.golang.org/appengine"
|
|
|
| "github.com/luci/gae/filter/dscache"
|
| "github.com/luci/gae/impl/prod"
|
| "github.com/luci/luci-go/appengine/gaeauth/client"
|
| "github.com/luci/luci-go/appengine/gaeauth/server"
|
| "github.com/luci/luci-go/appengine/gaeauth/server/gaesigner"
|
| "github.com/luci/luci-go/appengine/gaesecrets"
|
| "github.com/luci/luci-go/appengine/gaesettings"
|
| "github.com/luci/luci-go/appengine/tsmon"
|
| "github.com/luci/luci-go/common/cacheContext"
|
| "github.com/luci/luci-go/common/logging"
|
| "github.com/luci/luci-go/server/auth"
|
| "github.com/luci/luci-go/server/middleware"
|
| "github.com/luci/luci-go/server/proccache"
|
| + "github.com/luci/luci-go/server/router"
|
| "github.com/luci/luci-go/server/settings"
|
| )
|
|
|
| var (
|
| // globalProcessCache holds state cached between requests.
|
| globalProcessCache = &proccache.Cache{}
|
|
|
| // globalSettings holds global app settings lazily updated from the datastore.
|
| globalSettings = settings.New(gaesettings.Storage{})
|
|
|
| @@ -67,23 +66,27 @@ func WithProd(c context.Context, req *http.Request) context.Context {
|
|
|
| // The rest of the service may use applied configuration.
|
| c = proccache.Use(c, globalProcessCache)
|
| c = client.UseAnonymousTransport(c)
|
| c = gaesecrets.Use(c, nil)
|
| c = gaesigner.Use(c)
|
| c = auth.UseDB(c, globalAuthDBCache)
|
| return cacheContext.Wrap(c)
|
| }
|
|
|
| -// BaseProd adapts a middleware-style handler to a httprouter.Handle.
|
| -//
|
| -// It installs services using WithProd, installs a panic catcher if this
|
| -// is not a devserver, and injects the monitoring middleware.
|
| -func BaseProd(h middleware.Handler) httprouter.Handle {
|
| - h = globalTsMonState.Middleware(h)
|
| - if !appengine.IsDevAppServer() {
|
| - h = middleware.WithPanicCatcher(h)
|
| +// ProdServices is a middleware that installs the set of standard production
|
| +// AppEngine services by calling WithProd.
|
| +func ProdServices(c *router.Context, next router.Handler) {
|
| + c.Context = WithProd(c.Context, c.Request)
|
| + next(c)
|
| +}
|
| +
|
| +// BaseProd returns a list of middleware: WithProd middleware, a panic catcher if this
|
| +// is not a devserver, and the monitoring middleware.
|
| +func BaseProd() router.MiddlewareChain {
|
| + if appengine.IsDevAppServer() {
|
| + return router.MiddlewareChain{ProdServices, globalTsMonState.Middleware}
|
| }
|
| - return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
| - h(WithProd(context.Background(), r), rw, r, p)
|
| + return router.MiddlewareChain{
|
| + ProdServices, middleware.WithPanicCatcher, globalTsMonState.Middleware,
|
| }
|
| }
|
|
|