Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user-agent used by buf curl #2475

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion private/buf/bufcurl/verbose_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func DefaultUserAgent(protocol string, bufVersion string) string {
if strings.Contains(protocol, "grpc") {
libUserAgent = "grpc-go-connect"
}
return fmt.Sprintf("buf/%s %s/%s (%s)", bufVersion, libUserAgent, connect.Version, runtime.Version())
return fmt.Sprintf("%s/%s (%s) buf/%s", libUserAgent, connect.Version, runtime.Version(), bufVersion)
}

// NewVerboseHTTPClient creates a new HTTP client with the given transport and
Expand Down
11 changes: 7 additions & 4 deletions private/buf/cmd/buf/command/curl/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,11 @@ func run(ctx context.Context, container appflag.Container, f *flags) (err error)
if err != nil {
return err
}
userAgent := f.UserAgent
if userAgent == "" {
userAgent = bufcurl.DefaultUserAgent(f.Protocol, bufcli.Version)
}
if len(requestHeaders.Values("user-agent")) == 0 {
userAgent := f.UserAgent
if userAgent == "" {
userAgent = bufcurl.DefaultUserAgent(f.Protocol, bufcli.Version)
}
requestHeaders.Set("user-agent", userAgent)
}
var basicCreds *string
Expand Down Expand Up @@ -885,6 +885,9 @@ func run(ctx context.Context, container appflag.Container, f *flags) (err error)
reflectHeaders.Set("authorization", creds)
}
}
if len(reflectHeaders.Values("user-agent")) == 0 {
reflectHeaders.Set("user-agent", userAgent)
}
reflectProtocol, err := bufcurl.ParseReflectProtocol(f.ReflectProtocol)
if err != nil {
return err
Expand Down