Chromium Code Reviews| Index: appengine/cmd/milo/settings/themes.go |
| diff --git a/appengine/cmd/milo/settings/themes.go b/appengine/cmd/milo/settings/themes.go |
| index 9d6e0cb350db766124cf690c91dd9046ecf4ee49..1ad06a4e82a99a08d7a96f5810578b008f9148d4 100644 |
| --- a/appengine/cmd/milo/settings/themes.go |
| +++ b/appengine/cmd/milo/settings/themes.go |
| @@ -21,7 +21,7 @@ import ( |
| "github.com/luci/luci-go/appengine/gaemiddleware" |
| "github.com/luci/luci-go/common/clock" |
| "github.com/luci/luci-go/server/auth" |
| - "github.com/luci/luci-go/server/middleware" |
| + "github.com/luci/luci-go/server/router" |
| "github.com/luci/luci-go/server/templates" |
| "golang.org/x/net/context" |
| ) |
| @@ -119,14 +119,14 @@ func UseNamedBundle(c context.Context, nb NamedBundle) (context.Context, error) |
| } |
| // withNamedBundle is like templates.WithTemplates, but with the choice of one of many bundles (themes) |
| -func withNamedBundle(h middleware.Handler, nb NamedBundle) middleware.Handler { |
| - return func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) { |
| - c, err := UseNamedBundle(c, nb) // calls EnsureLoaded and initializes b.err inside |
| +func withNamedBundle(nb NamedBundle) router.Handler { |
| + return func(c *router.Context) { |
| + var err error |
| + c.Context, err = UseNamedBundle(c.Context, nb) // calls EnsureLoaded and initializes b.err inside |
| if err != nil { |
| - http.Error(rw, fmt.Sprintf("Can't load HTML templates.\n%s", err), http.StatusInternalServerError) |
| - return |
| + http.Error(c.Writer, fmt.Sprintf("Can't load HTML templates.\n%s", err), http.StatusInternalServerError) |
| + c.Abort() |
| } |
| - h(c, rw, r, p) |
| } |
| } |
| @@ -148,45 +148,48 @@ func themedMustRender(c context.Context, out io.Writer, theme, name string, args |
| } |
| // Base adds the basic luci appengine middlewares. |
| -func Base(h middleware.Handler) httprouter.Handle { |
| +func Base() []router.Handler { |
| + // TODO(nishanths): Allocate h for total length instead of repeated append() |
| + // in loop. |
| methods := auth.Authenticator{ |
| &server.OAuth2Method{Scopes: []string{server.EmailScope}}, |
| server.CookieAuth, |
| &server.InboundAppIDAuthMethod{}, |
| } |
| + h := append(gaemiddleware.BaseProd(), auth.Use(methods)) |
| for _, nb := range GetTemplateBundles() { |
| - h = withNamedBundle(h, nb) |
| + h = append(h, withNamedBundle(nb)) |
| } |
| - return gaemiddleware.BaseProd(auth.Use(h, methods)) |
| + return h |
| } |
| // Wrap wraps Milo "Render" functions and emits a middleware.Handler function. Of note |
| // is that Render functions' interface into rendering is purely through a single |
| // templates.Args value which gets rendered here, while the http.ResponseWriter |
| // is stripped out. |
| -func Wrap(h ThemedHandler) func(http.ResponseWriter, *http.Request, httprouter.Params) { |
| - hx := func(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
| +func Wrap(h ThemedHandler) router.Handler { |
| + return func(c *router.Context) { |
| // Figure out if we need to do the things. |
| - theme := GetTheme(c, r) |
| + theme := GetTheme(c.Context, c.Request) |
| template := h.GetTemplateName(theme) |
| // Do the things. |
| - args, err := h.Render(c, r, p) |
| + args, err := h.Render(c.Context, c.Request, c.Params) |
| // Throw errors. |
| // TODO(hinoka): Add themes and templates for errors so they look better. |
| if err != nil { |
| if merr, ok := err.(*miloerror.Error); ok { |
| - http.Error(w, merr.Message, merr.Code) |
| + http.Error(c.Writer, merr.Message, merr.Code) |
| } else { |
| - http.Error(w, err.Error(), http.StatusInternalServerError) |
| + http.Error(c.Writer, err.Error(), http.StatusInternalServerError) |
| } |
| + c.Abort() |
| return |
| } |
| // Render the stuff. |
| name := fmt.Sprintf("pages/%s", template) |
| - themedMustRender(c, w, theme.Name, name, *args) |
| + themedMustRender(c.Context, c.Writer, theme.Name, name, *args) |
| } |
| - return Base(hx) |
|
hinoka
2016/06/13 18:31:20
Don't we still need to install the base middleware
nishanths
2016/06/15 18:25:08
You're right. :) But they were now being added at
|
| } |