Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Unified Diff: appengine/gaemiddleware/context.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Convert remaining source files Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/gaemiddleware/context.go
diff --git a/appengine/gaemiddleware/context.go b/appengine/gaemiddleware/context.go
index 60a8bce83791c2a309cd777a9bd2c7ade7e19373..57b0d886685b9fdb264e0bf0ff8be48c866bb1df 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,35 @@ 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,
}
}

Powered by Google App Engine
This is Rietveld 408576698