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

Unified Diff: appengine/cmd/milo/settings/settings.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 side-by-side diff with in-line comments
Download patch
Index: appengine/cmd/milo/settings/settings.go
diff --git a/appengine/cmd/milo/settings/settings.go b/appengine/cmd/milo/settings/settings.go
index d7fb7399be6c4f605603306a8383b8dbb479a508..f51b78345358131a951e420a433de1d525f96cb3 100644
--- a/appengine/cmd/milo/settings/settings.go
+++ b/appengine/cmd/milo/settings/settings.go
@@ -10,13 +10,13 @@ import (
"fmt"
"net/http"
- "github.com/julienschmidt/httprouter"
"github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/appengine/cmd/milo/model"
"github.com/luci/luci-go/appengine/cmd/milo/resp"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/identity"
"github.com/luci/luci-go/server/auth/xsrf"
+ "github.com/luci/luci-go/server/router"
"golang.org/x/net/context"
)
@@ -75,31 +75,31 @@ func getCookieSettings(c context.Context, r *http.Request) *model.UserConfig {
// ChangeSettings is invoked in a POST request to settings and changes either
// the user settings in the datastore, or the cookies if user is anon.
-func ChangeSettings(c context.Context, h http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func ChangeSettings(c *router.Context) {
// First, check XSRF token.
- err := xsrf.Check(c, r.FormValue("xsrf_token"))
+ err := xsrf.Check(c.Context, c.Request.FormValue("xsrf_token"))
if err != nil {
- h.WriteHeader(http.StatusUnauthorized)
- h.Write([]byte("Failed XSRF check."))
+ c.Writer.WriteHeader(http.StatusUnauthorized)
+ c.Writer.Write([]byte("Failed XSRF check."))
return
}
u := &updateReq{
- Theme: r.FormValue("theme"),
+ Theme: c.Request.FormValue("theme"),
}
validateUpdate(u)
- s := getUserSettings(c)
+ s := getUserSettings(c.Context)
if s == nil {
// User doesn't exist, just respond with a cookie.
- s = getCookieSettings(c, r)
+ s = getCookieSettings(c.Context, c.Request)
s.Theme = u.Theme
- setCookieSettings(h, s)
+ setCookieSettings(c.Writer, s)
} else {
- changeUserSettings(c, u)
+ changeUserSettings(c.Context, u)
}
// Redirect to the GET endpoint.
- http.Redirect(h, r, r.URL.String(), http.StatusSeeOther)
+ http.Redirect(c.Writer, c.Request, c.Request.URL.String(), http.StatusSeeOther)
}
// setCookieSettings sets the cfg object as a base64 json serialized string.

Powered by Google App Engine
This is Rietveld 408576698