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

Unified Diff: logdog/server/service/rt.go

Issue 2643363002: LogDog: Use server/auth for authentication. (Closed)
Patch Set: LogDog: Use server/auth for authentication. Created 3 years, 11 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 | « logdog/server/cmd/logdog_collector/main.go ('k') | logdog/server/service/service.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: logdog/server/service/rt.go
diff --git a/logdog/server/service/rt.go b/logdog/server/service/rt.go
new file mode 100644
index 0000000000000000000000000000000000000000..4630b84c33071ea709c92f675572cb322f76e2bc
--- /dev/null
+++ b/logdog/server/service/rt.go
@@ -0,0 +1,40 @@
+// Copyright 2017 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 service
+
+import (
+ "net/http"
+ "strings"
+
+ commonAuth "github.com/luci/luci-go/common/auth"
+)
+
+type serviceModifyingTransport struct {
+ userAgent string
+}
+
+func (smt *serviceModifyingTransport) roundTripper(base http.RoundTripper) http.RoundTripper {
+ if base == nil {
+ base = http.DefaultTransport
+ }
+
+ return commonAuth.NewModifyingTransport(base, func(req *http.Request) error {
+ // Set a user agent based on our service. If an existing user agent is
+ // specified, add it onto the end of the string.
+ parts := make([]string, 0, 2)
+ for _, part := range []string{
+ smt.userAgent,
+ req.UserAgent(),
+ } {
+ if part != "" {
+ parts = append(parts, part)
+ }
+ }
+ if len(parts) > 0 {
+ req.Header.Set("User-Agent", strings.Join(parts, " / "))
+ }
+ return nil
+ })
+}
« no previous file with comments | « logdog/server/cmd/logdog_collector/main.go ('k') | logdog/server/service/service.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698