mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-09 13:18:46 +00:00
gRPC client: Strip "grpc-go/version" suffix from User-Agent header (#5689)
Fixes https://github.com/XTLS/Xray-core/pull/5658#issuecomment-3894269376 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
func TestConfig_GetServiceName(t *testing.T) {
|
||||
@@ -115,3 +118,12 @@ func TestConfig_GetTunMultiStreamName(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetUserAgent(t *testing.T) {
|
||||
ua := "Test/1.0"
|
||||
conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUserAgent(ua))
|
||||
assert.NoError(t, err)
|
||||
defer conn.Close()
|
||||
setUserAgent(conn, ua)
|
||||
assert.Equal(t, ua, reflect.ValueOf(conn).Elem().FieldByName("dopts").FieldByName("copts").FieldByName("UserAgent").String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user