MCPcopy Index your code
hub / github.com/coder/coder / wrapTransportWithUserAgentHeader

Function wrapTransportWithUserAgentHeader

cli/root.go:1684–1696  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
1684func 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
1698type roundTripper func(req *http.Request) (*http.Response, error)
1699

Callers 1

createHTTPClientMethod · 0.85

Calls 6

VersionFunction · 0.92
roundTripperFuncType · 0.70
DoMethod · 0.65
SetMethod · 0.65
FullNameMethod · 0.45
RoundTripMethod · 0.45

Tested by

no test coverage detected