| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package gaemiddleware | 5 package gaemiddleware |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 "golang.org/x/net/context" |
| 10 "google.golang.org/appengine" | 11 "google.golang.org/appengine" |
| 11 | 12 |
| 12 "github.com/julienschmidt/httprouter" | |
| 13 "golang.org/x/net/context" | |
| 14 | |
| 15 "github.com/luci/gae/filter/dscache" | 13 "github.com/luci/gae/filter/dscache" |
| 16 "github.com/luci/gae/impl/prod" | 14 "github.com/luci/gae/impl/prod" |
| 17 "github.com/luci/luci-go/appengine/gaeauth/client" | 15 "github.com/luci/luci-go/appengine/gaeauth/client" |
| 18 "github.com/luci/luci-go/appengine/gaeauth/server" | 16 "github.com/luci/luci-go/appengine/gaeauth/server" |
| 19 "github.com/luci/luci-go/appengine/gaeauth/server/gaesigner" | 17 "github.com/luci/luci-go/appengine/gaeauth/server/gaesigner" |
| 20 "github.com/luci/luci-go/appengine/gaesecrets" | 18 "github.com/luci/luci-go/appengine/gaesecrets" |
| 21 "github.com/luci/luci-go/appengine/gaesettings" | 19 "github.com/luci/luci-go/appengine/gaesettings" |
| 22 "github.com/luci/luci-go/appengine/tsmon" | 20 "github.com/luci/luci-go/appengine/tsmon" |
| 23 "github.com/luci/luci-go/common/cacheContext" | 21 "github.com/luci/luci-go/common/cacheContext" |
| 24 "github.com/luci/luci-go/common/logging" | 22 "github.com/luci/luci-go/common/logging" |
| 25 "github.com/luci/luci-go/server/auth" | 23 "github.com/luci/luci-go/server/auth" |
| 26 "github.com/luci/luci-go/server/middleware" | 24 "github.com/luci/luci-go/server/middleware" |
| 27 "github.com/luci/luci-go/server/proccache" | 25 "github.com/luci/luci-go/server/proccache" |
| 26 "github.com/luci/luci-go/server/router" |
| 28 "github.com/luci/luci-go/server/settings" | 27 "github.com/luci/luci-go/server/settings" |
| 29 ) | 28 ) |
| 30 | 29 |
| 31 var ( | 30 var ( |
| 32 // globalProcessCache holds state cached between requests. | 31 // globalProcessCache holds state cached between requests. |
| 33 globalProcessCache = &proccache.Cache{} | 32 globalProcessCache = &proccache.Cache{} |
| 34 | 33 |
| 35 // globalSettings holds global app settings lazily updated from the data
store. | 34 // globalSettings holds global app settings lazily updated from the data
store. |
| 36 globalSettings = settings.New(gaesettings.Storage{}) | 35 globalSettings = settings.New(gaesettings.Storage{}) |
| 37 | 36 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 | 66 |
| 68 // The rest of the service may use applied configuration. | 67 // The rest of the service may use applied configuration. |
| 69 c = proccache.Use(c, globalProcessCache) | 68 c = proccache.Use(c, globalProcessCache) |
| 70 c = client.UseAnonymousTransport(c) | 69 c = client.UseAnonymousTransport(c) |
| 71 c = gaesecrets.Use(c, nil) | 70 c = gaesecrets.Use(c, nil) |
| 72 c = gaesigner.Use(c) | 71 c = gaesigner.Use(c) |
| 73 c = auth.UseDB(c, globalAuthDBCache) | 72 c = auth.UseDB(c, globalAuthDBCache) |
| 74 return cacheContext.Wrap(c) | 73 return cacheContext.Wrap(c) |
| 75 } | 74 } |
| 76 | 75 |
| 77 // BaseProd adapts a middleware-style handler to a httprouter.Handle. | 76 // ProdServices is a middleware that installs the set of standard production |
| 78 // | 77 // AppEngine services by calling WithProd. |
| 79 // It installs services using WithProd, installs a panic catcher if this | 78 func ProdServices(c *router.Context, next router.Handler) { |
| 80 // is not a devserver, and injects the monitoring middleware. | 79 » c.Context = WithProd(c.Context, c.Request) |
| 81 func BaseProd(h middleware.Handler) httprouter.Handle { | 80 » next(c) |
| 82 » h = globalTsMonState.Middleware(h) | 81 } |
| 83 » if !appengine.IsDevAppServer() { | 82 |
| 84 » » h = middleware.WithPanicCatcher(h) | 83 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i
f this |
| 84 // is not a devserver, and the monitoring middleware. |
| 85 func BaseProd() router.MiddlewareChain { |
| 86 » if appengine.IsDevAppServer() { |
| 87 » » return router.MiddlewareChain{ProdServices, globalTsMonState.Mid
dleware} |
| 85 } | 88 } |
| 86 » return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params
) { | 89 » return router.MiddlewareChain{ |
| 87 » » h(WithProd(context.Background(), r), rw, r, p) | 90 » » ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd
leware, |
| 88 } | 91 } |
| 89 } | 92 } |
| OLD | NEW |