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

Unified Diff: server/auth/handlers.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd 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
« no previous file with comments | « server/auth/db.go ('k') | server/auth/info/info.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/handlers.go
diff --git a/server/auth/handlers.go b/server/auth/handlers.go
index 525d56dbdb69ee1da86a381bd5c8a30ed5092abe..a1e0ccfb6569762ae57eedede5e2270b5a480399 100644
--- a/server/auth/handlers.go
+++ b/server/auth/handlers.go
@@ -1,53 +1,51 @@
// Copyright 2015 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package auth
import (
"encoding/json"
"net/http"
- "github.com/julienschmidt/httprouter"
- "golang.org/x/net/context"
-
"github.com/luci/luci-go/common/logging"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
)
// InstallHandlers installs HTTP handlers that return information useful for
// debugging authentication issues.
//
// This is optional. If you using appengine/gaeauth/server, these handlers are
// already installed.
-func InstallHandlers(r *httprouter.Router, base middleware.Base) {
- r.GET("/auth/api/v1/accounts/self", base(Authenticate(accountsSelfHandler)))
+func InstallHandlers(r *router.Router, base router.MiddlewareChain) {
+ mc := append(base, Authenticate)
+ r.GET("/auth/api/v1/accounts/self", mc, accountsSelfHandler)
}
// accountsSelfHandler returns JSON with information about the caller.
//
// It can be used to verify callers' IP, access tokens, etc.
-func accountsSelfHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func accountsSelfHandler(c *router.Context) {
var reply struct {
Error string `json:"error,omitempty"`
Identity string `json:"identity,omitempty"`
IP string `json:"ip,omitempty"`
}
- state := GetState(c)
+ state := GetState(c.Context)
if state == nil {
reply.Error = "Auth state is not available, application is probably using auth library wrong."
} else {
reply.Identity = string(state.User().Identity)
reply.IP = state.PeerIP().String()
}
- rw.Header().Set("Content-Type", "application/json; charset=utf-8")
+ c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
if reply.Error == "" {
- rw.WriteHeader(http.StatusOK)
+ c.Writer.WriteHeader(http.StatusOK)
} else {
- rw.WriteHeader(http.StatusNotImplemented)
- logging.Errorf(c, "HTTP 501 - %s", reply.Error)
+ c.Writer.WriteHeader(http.StatusNotImplemented)
+ logging.Errorf(c.Context, "HTTP 501 - %s", reply.Error)
}
- json.NewEncoder(rw).Encode(&reply)
+ json.NewEncoder(c.Writer).Encode(&reply)
}
« no previous file with comments | « server/auth/db.go ('k') | server/auth/info/info.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698