Skip to content

Commit

Permalink
Fix user-agent used by buf curl (#2475)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump authored Oct 4, 2023
1 parent e4afbcf commit b9d582d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit b9d582d

Please sign in to comment.