Skip to content

Commit

Permalink
feat: add support for user-agent header (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
gszr committed Sep 4, 2020
1 parent ba5f667 commit 9846afc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/grpcurl/grpcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import (
// the response status codes emitted use an offest of 64
const statusCodeOffset = 64

var version = "dev build <no version set>"
const no_version = "dev build <no version set>"

var version = no_version

var (
exit = os.Exit
Expand Down Expand Up @@ -85,6 +87,10 @@ var (
is used, this will also be used as the server name when verifying the
server's certificate. It defaults to the address that is provided in the
positional arguments.`))
userAgent = flags.String("user-agent", "", prettify(`
If set, the specified value will be added to the User-Agent header set
by the grpc-go library.
`))
data = flags.String("d", "", prettify(`
Data for request contents. If the value is '@' then the request contents
are read from stdin. For calls that accept a stream of requests, the
Expand Down Expand Up @@ -426,6 +432,16 @@ func main() {
} else if *authority != "" {
opts = append(opts, grpc.WithAuthority(*authority))
}

grpcurlUA := "grpcurl/" + version
if version == no_version {
grpcurlUA = "grpcurl/dev-build (no version set)"
}
if *userAgent != "" {
grpcurlUA = *userAgent + " " + grpcurlUA
}
opts = append(opts, grpc.WithUserAgent(grpcurlUA))

network := "tcp"
if isUnixSocket != nil && isUnixSocket() {
network = "unix"
Expand Down

0 comments on commit 9846afc

Please sign in to comment.