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

Side by Side 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: Update tests 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 unified diff | Download patch
OLDNEW
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 "google.golang.org/appengine" 10 "google.golang.org/appengine"
11 11
12 "github.com/julienschmidt/httprouter"
13 "golang.org/x/net/context" 12 "golang.org/x/net/context"
14 13
15 "github.com/luci/gae/filter/dscache" 14 "github.com/luci/gae/filter/dscache"
16 "github.com/luci/gae/impl/prod" 15 "github.com/luci/gae/impl/prod"
17 "github.com/luci/luci-go/appengine/gaeauth/client" 16 "github.com/luci/luci-go/appengine/gaeauth/client"
18 "github.com/luci/luci-go/appengine/gaeauth/server" 17 "github.com/luci/luci-go/appengine/gaeauth/server"
19 "github.com/luci/luci-go/appengine/gaeauth/server/gaesigner" 18 "github.com/luci/luci-go/appengine/gaeauth/server/gaesigner"
20 "github.com/luci/luci-go/appengine/gaesecrets" 19 "github.com/luci/luci-go/appengine/gaesecrets"
21 "github.com/luci/luci-go/appengine/gaesettings" 20 "github.com/luci/luci-go/appengine/gaesettings"
22 "github.com/luci/luci-go/appengine/tsmon" 21 "github.com/luci/luci-go/appengine/tsmon"
23 "github.com/luci/luci-go/common/cacheContext" 22 "github.com/luci/luci-go/common/cacheContext"
24 "github.com/luci/luci-go/common/logging" 23 "github.com/luci/luci-go/common/logging"
25 "github.com/luci/luci-go/server/auth" 24 "github.com/luci/luci-go/server/auth"
26 "github.com/luci/luci-go/server/middleware" 25 "github.com/luci/luci-go/server/middleware"
27 "github.com/luci/luci-go/server/proccache" 26 "github.com/luci/luci-go/server/proccache"
27 "github.com/luci/luci-go/server/router"
28 "github.com/luci/luci-go/server/settings" 28 "github.com/luci/luci-go/server/settings"
29 ) 29 )
30 30
31 var ( 31 var (
32 // globalProcessCache holds state cached between requests. 32 // globalProcessCache holds state cached between requests.
33 globalProcessCache = &proccache.Cache{} 33 globalProcessCache = &proccache.Cache{}
34 34
35 // globalSettings holds global app settings lazily updated from the data store. 35 // globalSettings holds global app settings lazily updated from the data store.
36 globalSettings = settings.New(gaesettings.Storage{}) 36 globalSettings = settings.New(gaesettings.Storage{})
37 37
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 c = gaesecrets.Use(c, nil) 71 c = gaesecrets.Use(c, nil)
72 c = gaesigner.Use(c) 72 c = gaesigner.Use(c)
73 c = auth.UseDB(c, globalAuthDBCache) 73 c = auth.UseDB(c, globalAuthDBCache)
74 return cacheContext.Wrap(c) 74 return cacheContext.Wrap(c)
75 } 75 }
76 76
77 // BaseProd adapts a middleware-style handler to a httprouter.Handle. 77 // BaseProd adapts a middleware-style handler to a httprouter.Handle.
78 // 78 //
79 // It installs services using WithProd, installs a panic catcher if this 79 // It installs services using WithProd, installs a panic catcher if this
80 // is not a devserver, and injects the monitoring middleware. 80 // is not a devserver, and injects the monitoring middleware.
81 func BaseProd(h middleware.Handler) httprouter.Handle { 81 func BaseProd() []router.Handler {
82 » h = globalTsMonState.Middleware(h) 82 » var h []router.Handler
83 » h = append(h, func(c *router.Context) {
84 » » c.Context = WithProd(context.Background(), c.Request)
85 » })
83 if !appengine.IsDevAppServer() { 86 if !appengine.IsDevAppServer() {
84 » » h = middleware.WithPanicCatcher(h) 87 » » h = append(h, middleware.WithPanicCatcher())
85 } 88 }
86 » return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) { 89 » h = append(h, globalTsMonState.Middleware())
87 » » h(WithProd(context.Background(), r), rw, r, p) 90 » return h
88 » }
89 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698