feat: add support for user-agent header (#182)

This commit is contained in:
Guilherme Salazar 2020-09-04 12:31:28 -03:00 committed by GitHub
parent ba5f667e13
commit 9846afccbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -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
@ -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
@ -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"