feat: add support for user-agent header
Given value is added to the user-agent header set by the grpc-go library.
This commit is contained in:
parent
e544b9e66f
commit
b44d1e1d0f
|
|
@ -37,7 +37,9 @@ import (
|
||||||
// the response status codes emitted use an offest of 64
|
// the response status codes emitted use an offest of 64
|
||||||
const statusCodeOffset = 64
|
const statusCodeOffset = 64
|
||||||
|
|
||||||
var version = "dev build <no version set>"
|
const no_version = "dev build <no version set>"
|
||||||
|
|
||||||
|
var version = no_version
|
||||||
|
|
||||||
var (
|
var (
|
||||||
exit = os.Exit
|
exit = os.Exit
|
||||||
|
|
@ -85,6 +87,10 @@ var (
|
||||||
is used, this will also be used as the server name when verifying the
|
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
|
server's certificate. It defaults to the address that is provided in the
|
||||||
positional arguments.`))
|
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 = flags.String("d", "", prettify(`
|
||||||
Data for request contents. If the value is '@' then the request contents
|
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
|
are read from stdin. For calls that accept a stream of requests, the
|
||||||
|
|
@ -426,6 +432,16 @@ func main() {
|
||||||
} else if *authority != "" {
|
} else if *authority != "" {
|
||||||
opts = append(opts, grpc.WithAuthority(*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"
|
network := "tcp"
|
||||||
if isUnixSocket != nil && isUnixSocket() {
|
if isUnixSocket != nil && isUnixSocket() {
|
||||||
network = "unix"
|
network = "unix"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue