Chromium Code Reviews| Index: appengine/gaemiddleware/context.go |
| diff --git a/appengine/gaemiddleware/context.go b/appengine/gaemiddleware/context.go |
| index 60a8bce83791c2a309cd777a9bd2c7ade7e19373..a4728ec296a78620de7350ef04b1b8ec07a1bcae 100644 |
| --- a/appengine/gaemiddleware/context.go |
| +++ b/appengine/gaemiddleware/context.go |
| @@ -5,13 +5,8 @@ |
| package gaemiddleware |
| import ( |
| - "net/http" |
| - |
| "google.golang.org/appengine" |
| - "github.com/julienschmidt/httprouter" |
| - "golang.org/x/net/context" |
| - |
| "github.com/luci/gae/filter/dscache" |
| "github.com/luci/gae/impl/prod" |
| "github.com/luci/luci-go/appengine/gaeauth/client" |
| @@ -25,6 +20,7 @@ import ( |
| "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" |
| ) |
| @@ -52,38 +48,36 @@ var ( |
| // * github.com/luci/luci-go/appengine/gaesecrets (access to secret keys in datastore) |
| // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) |
| // * github.com/luci/luci-go/appengine/gaeauth/server/auth (user groups database) |
| -func WithProd(c context.Context, req *http.Request) context.Context { |
| +func WithProd(c *router.Context, next router.Handler) { |
| // These are needed to use fetchCachedSettings. |
| - c = logging.SetLevel(c, logging.Debug) |
| - c = prod.Use(c, req) |
| - c = settings.Use(c, globalSettings) |
| + c.Context = logging.SetLevel(c.Context, logging.Debug) |
| + c.Context = prod.Use(c.Context, c.Request) |
| + c.Context = settings.Use(c.Context, globalSettings) |
| // Fetch and apply configuration stored in the datastore. |
| - settings := fetchCachedSettings(c) |
| - c = logging.SetLevel(c, settings.LoggingLevel) |
| + settings := fetchCachedSettings(c.Context) |
| + c.Context = logging.SetLevel(c.Context, settings.LoggingLevel) |
| if !settings.DisableDSCache { |
| - c = dscache.AlwaysFilterRDS(c, nil) |
| + c.Context = dscache.AlwaysFilterRDS(c.Context, nil) |
| } |
| // 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) |
| + c.Context = proccache.Use(c.Context, globalProcessCache) |
| + c.Context = client.UseAnonymousTransport(c.Context) |
| + c.Context = gaesecrets.Use(c.Context, nil) |
| + c.Context = gaesigner.Use(c.Context) |
| + c.Context = auth.UseDB(c.Context, globalAuthDBCache) |
| + c.Context = cacheContext.Wrap(c.Context) |
| } |
| -// 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) |
| +// 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{WithProd, globalTsMonState.Middleware} |
| } |
| - return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params) { |
| - h(WithProd(context.Background(), r), rw, r, p) |
| + return router.MiddlewareChain{ |
| + WithProd, middleware.WithPanicCatcher, globalTsMonState.Middleware, |
| } |
| + |
|
Vadim Sh.
2016/06/18 16:57:20
nit: remove this new line :)
nishanths
2016/06/19 02:47:02
Done :)
|
| } |