From 65358c24f657a7dba4565a133ecdaaf603282ba3 Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Thu, 27 Feb 2025 18:26:43 +0100 Subject: [PATCH] QGrpcHttp2Channel: Add user-agent header The protocol does not require a user-agent, but it is recommended to provide a structured user-agent string. This helps diagnose issues more effectively in heterogeneous environments. Ref: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#user-agents [ChangeLog][GRPC][QGrpcHttp2Channel] Added a structured user-agent string to the request headers. Task-number: QTBUG-133254 Change-Id: Ic312f2a3754108798bb7acc70e2d8bed4a891401 Reviewed-by: Alexey Edelev --- src/grpc/qgrpchttp2channel.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index 5a44bd2a..700dc90a 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -481,6 +481,10 @@ void Http2Handler::prepareInitialRequest(QGrpcOperationContext *operationContext const static QByteArray GrpcServiceNameHeader("service-name"); const static QByteArray GrpcAcceptEncodingHeader("grpc-accept-encoding"); const static QByteArray GrpcAcceptEncodingValue("identity,deflate,gzip"); + const static QByteArray UserAgentHeader("user-agent"); + const static QByteArray UserAgentValue("grpc-c++-qtgrpc/"_ba + QT_VERSION_STR + " ("_ba + + QSysInfo::productType().toUtf8() + '/' + + QSysInfo::productVersion().toUtf8() + ')'); const auto &channelOptions = channel->q_ptr->channelOptions(); QByteArray service{ operationContext->service() }; @@ -494,6 +498,7 @@ void Http2Handler::prepareInitialRequest(QGrpcOperationContext *operationContext { GrpcServiceNameHeader, service }, { GrpcAcceptEncodingHeader, GrpcAcceptEncodingValue }, { AcceptEncodingHeader, AcceptEncodingValue }, + { UserAgentHeader, UserAgentValue }, { TEHeader, TEValue }, };