diff --git a/pkg/ctx/agentctx.go b/pkg/ctx/agentctx.go index 1fe79a1eee..74eda0b563 100644 --- a/pkg/ctx/agentctx.go +++ b/pkg/ctx/agentctx.go @@ -38,6 +38,7 @@ func ContextGetUserAgent(ctx context.Context) (*ua.UserAgent, bool) { return nil, false } +// ContextGetUserAgentString returns the user agent string if set in the given context. func ContextGetUserAgentString(ctx context.Context) (string, bool) { md, ok := metadata.FromIncomingContext(ctx) if !ok { diff --git a/pkg/useragent/useragent.go b/pkg/useragent/useragent.go index 238b058995..53d766ed26 100644 --- a/pkg/useragent/useragent.go +++ b/pkg/useragent/useragent.go @@ -47,7 +47,7 @@ func isGRPC(ua *ua.UserAgent) bool { return strings.HasPrefix(ua.Name, "grpc") } -// GetCategory returns the category of the user agent +// getCategory returns the category of the user agent // (i.e. if it is a web, mobile, desktop or grpc user agent) func getCategory(ua *ua.UserAgent) string { switch { @@ -64,6 +64,8 @@ func getCategory(ua *ua.UserAgent) string { } } +// IsUserAgentAllowed return true if the user agent corresponds +// to one in the allowed user agents list func IsUserAgentAllowed(ua *ua.UserAgent, allowedUserAgents []string) bool { cat := getCategory(ua) for _, userAgent := range allowedUserAgents {