wrapTransportWithUserAgentHeader sets a User-Agent header for all CLI requests that includes the CLI version, os/arch, and the specific command being run.
(transport http.RoundTripper, inv *serpent.Invocation)
| 1682 | // wrapTransportWithUserAgentHeader sets a User-Agent header for all CLI requests |
| 1683 | // that includes the CLI version, os/arch, and the specific command being run. |
| 1684 | func wrapTransportWithUserAgentHeader(transport http.RoundTripper, inv *serpent.Invocation) http.RoundTripper { |
| 1685 | var ( |
| 1686 | userAgent string |
| 1687 | once sync.Once |
| 1688 | ) |
| 1689 | return roundTripper(func(req *http.Request) (*http.Response, error) { |
| 1690 | once.Do(func() { |
| 1691 | userAgent = fmt.Sprintf("coder-cli/%s (%s/%s; %s)", buildinfo.Version(), runtime.GOOS, runtime.GOARCH, inv.Command.FullName()) |
| 1692 | }) |
| 1693 | req.Header.Set("User-Agent", userAgent) |
| 1694 | return transport.RoundTrip(req) |
| 1695 | }) |
| 1696 | } |
| 1697 | |
| 1698 | type roundTripper func(req *http.Request) (*http.Response, error) |
| 1699 |
no test coverage detected