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 <alexey.edelev@qt.io>
This commit is contained in:
Dennis Oberst 2025-02-27 18:26:43 +01:00
parent 684e96caa3
commit 65358c24f6
1 changed files with 5 additions and 0 deletions

View File

@ -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 },
};