Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package service | |
| 6 | |
| 7 import ( | |
| 8 "net/http" | |
| 9 "strings" | |
| 10 | |
| 11 commonAuth "github.com/luci/luci-go/common/auth" | |
| 12 ) | |
| 13 | |
| 14 type serviceModifyingTransport struct { | |
| 15 userAgent string | |
| 16 } | |
| 17 | |
| 18 func (smt *serviceModifyingTransport) roundTripper(base http.RoundTripper) http. RoundTripper { | |
|
iannucci
2017/01/21 00:37:00
this seems like maybe we should do this everywhere
| |
| 19 if base == nil { | |
| 20 base = http.DefaultTransport | |
| 21 } | |
| 22 | |
| 23 return commonAuth.NewModifyingTransport(base, func(req *http.Request) er ror { | |
| 24 // Set a user agent based on our service. If an existing user ag ent is | |
| 25 // specified, add it onto the end of the string. | |
| 26 parts := make([]string, 0, 2) | |
| 27 for _, part := range []string{ | |
| 28 smt.userAgent, | |
| 29 req.UserAgent(), | |
| 30 } { | |
| 31 if part != "" { | |
| 32 parts = append(parts, part) | |
| 33 } | |
| 34 } | |
| 35 if len(parts) > 0 { | |
| 36 req.Header.Set("User-Agent", strings.Join(parts, " / ")) | |
| 37 } | |
| 38 return nil | |
| 39 }) | |
| 40 } | |
| OLD | NEW |